Filter data in Excel and write each value to new sheet

I have a column filter in excel (for example, the value are A, B, C).
I want to copy each value to new different sheets.
I use the code that have been advised in other post as below:

1 read range of the first file (DT_Unfiltered)
2 assign DT_Filtered = DT_Unfiltered.Select("[Column1] = ‘Criteria1’").CopyToDatatable
3 write range to the second (DT_Filtered)

However, the problem I get is sometime my original file (filtered file) has full 3 values (A, B, C), but sometimes it just have A & B, so the code will be wrong & get bug. (because it cannot find C).
Could you please help me? thank you!

1 Like

Welcome to uipath community
Fine did we try with expression
dt = dt.Asenumerable().Where(Function(a) a.Field(of string)(“yourcolumnname”).ToString.Contains(“your keyword”)).CopyToDatatable()

Cheers @Li_Pham


I have tried your code however, I cannot get the value “A” in column Product out. what type of variable it is? (data table?)
Because I am new, so I cannot attach file for you.
Thank you for your support!

(From line in DT_Unfiltered.Select where COnvert.Tostring(line("[Column1]")).Trim.equals(Convert.ToString(Criteria1).Trim) select line).CopyToDatatable


Your keyword mentioned above implies either A or B or C

So the expression be like this
dt = dt.Asenumerable().Where(Function(a) a.Field(of string)(“yourcolumnname”).ToString.Contains(“A”)).CopyToDatatable()

Where dt is the variable of type datatable

And if we want to include two or more conditions along the expression
dt = dt.Asenumerable().Where(Function(a) a.Field(of string)(“yourcolumnname”).ToString.Contains(“A”) OR a.Field(of string)(“yourcolumnname”).ToString.Contains(“B”) ).CopyToDatatable()

Cheers @Li_Pham


Thank you so much! I got it :smiley:

1 Like

Thank you so much :smiley:

cheers @Li_Pham

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.