Remove Data Row based on value in a specific column

My goal with this is to copy two Excel files to DataTables. dtPrimary and dtPrevious.

If Column 5 in dtPrevious Matches dtPrimary I wish to delete the line from the DataTable. So my Flow goes like this:

For Each Row in dtPrimary
For Each Row in dtPrevious
IF Row.item(5).ToString = line.item(5).ToString

(Assign) varDuplicateRow = Row

(Remove Data Row) Row:varDuplicateRow. Datatable = dtPrimary

But I get the following Error Message:
If: This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.

Any ideas?

Use the Remove Duplicate Rows activity instead of trying to do it manually.


Use this to remove matched rows

Way one

  1. Use join datatable with full option and then filter datatable with non empty rows in second table related columns

Way two

  1. Use linq dt1.AsEnumerable.Where(function(x) Not dt2.AsEnumerable.Any(function(y) y(4).ToString=x(4).ToString)).CopyToDataTable


1 Like

Hi @steve1977beyond

Can you try this-

  1. For each row in dtPrevious, you initialize a Boolean variable varMatchFound to False.

  2. You then iterate through each row in dtPrimary to check if there is a match in Column 5 between the current row in dtPrevious and any row in dtPrimary. If a match is found, you set varMatchFound to True and break out of the inner loop using the “Break” activity.

  3. After the inner loop completes, you check the value of varMatchFound. If it’s True, it means a match was found in dtPrimary, so you remove the corresponding row from dtPrimary.

This approach ensures that you only remove rows from dtPrimary when a match is found in dtPrevious and avoids the error you encountered.

It will only be the one field it’s checking though as the info in the other fields will be different. Essentially, when both Data Tables have been compared, anything where a specific field is the same (regardless of what the others say), I wish to delete the complete line


Please try the above linq …it shpuld do the task for you


Thank you, I wasn’t really familiar with LINQ but it has solved this perfectly

1 Like

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