Delete rows from excel file except

I found a previous post (How to delete a row in excel based on condition - #3 by asatheeshk21) which was very useful but this deleted specific rows based on a criteria using the Assign functuion.

This used the statement
customerDT.AsEnumerable.Where(Function(x)Not(x(“Customer Details”).ToString.ToLower.Equals(“customer1”) or x(“Customer Details”).ToString.ToLower.Equals("customer1))).CopyToDataTable

Alas, I am not brilliant with functions but this works so well, I want to reuse it, but instead of removing the rows where Customer Details = Customer1 or Customer3, I want to retain those rows and delete everything else. I have tried a couple of things, but to no avail.

Could anybody assist please


Hi @gary.cobden ,

Try the below linq expression to achieve your new requirement. I have tested it is working fine at my end. thanks.

customerDT.AsEnumerable().Where(Function(row) row(“Customer Details”).ToString.ToLower.Equals(“customer1”) OR row(“Customer Details”).ToString.ToLower.Equals(“customer3”)).CopyToDataTable

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