Hi @fairymemay ,
Could you give this a try and see if it works out for you?
First, you have to declare a Dictionary(Of String, Tuple(Of Double, Double, Integer))
→
dt_configRate.AsEnumerable().ToDictionary(Function(k) k("Premium").ToString,Function(v) Tuple.Create(Convert.ToDouble(v("Rate").ToString.Replace(",","")),Convert.ToDouble(v("Rate2").ToString.Replace(",","")),CInt(v("Count").ToString)))
Next, you have to loop through each column value in the Configuration File and create a sheet in an Excel.
Collection of Sheets->
Enumerable.Range(0,dt_configRate.RowCount).Select(Function(s) dt_configRate.Rows(s)(0).ToString).ToArray()
Next, we have to populate a List of DataRows to check if the values are present or not before we copy them to a DataTable →
(From row In dt_sampleData.AsEnumerable()
Where dict(sheet).Item1<= Convert.ToDouble(row("FYP").ToString.Replace(",","")) AndAlso
dict(sheet).Item2 >= Convert.ToDouble(row("FYP").ToString.Replace(",",""))
Let ra = row.ItemArray.Take(2).Append(dict(sheet).Item3).Concat(row.ItemArray.Skip(3).ToArray()).ToArray()
Select dt_result.Rows.Add(ra)).ToList()
If so, then the ToList() to replaced with CopyToDataTable(), and if not, then we simply clone the original table(to get the headers) and add a Sheet there.

CreateSheetsAndSegregrateOnRates.xaml (11.7 KB)
Kind Regards,
Ashwin A.K.