i have an excel sheet and i need to filter column D with “2” then delete all the filtered rows
To filter column D with the value “2” and delete the filtered rows in UiPath, you can follow these steps:
- Use the “Excel Application Scope” activity to open the Excel file.
- Within the scope, use the “Read Range” activity to read the data from the Excel sheet into a DataTable variable, let’s say
dtData. - Use the “Filter Data Table” activity to filter the DataTable based on the condition in column D. Set the filter condition to
"[ColumnD] = '2'"(assuming the column name is “ColumnD”). - The filtered DataTable will be stored in a new DataTable variable, let’s say
dtFiltered. - Use the “For Each Row” activity to iterate through each row in
dtFiltered. - Inside the loop, use the “Delete Row” activity to delete the current row from
dtData. - After the loop completes, use the “Write Range” activity to write the updated
dtDataback to the Excel file, overwriting the previous data.
Thanks!!
Welcome to the community
Use filter excel activity and then use delete rows activity
Cheers
can you drop ex. xaml. please?
There are two recommended approaches to achieve this:
Read Excel → Filter DataTable (No LINQ)
- Read the Excel sheet into a DataTable.
- Use Filter Data Table activity with the condition:
Column D = "2"
- Use the filtered result to remove those rows from the original DataTable.
- Write the updated DataTable back to Excel.
Easier to understand and maintain
Recommended for beginners
LINQ Expression (Faster & Optimized)
- Read the Excel sheet into a DataTable.
- Use a LINQ Assign to exclude rows where Column D equals
"2".
Example:
dt = dt.AsEnumerable().
Where(Function(r) r(3).ToString <> "2").
CopyToDataTable()
Faster for large datasets
Cleaner and more efficient
Preferred for performance-critical automations
Conclusion:
- Use Filter DataTable for readability and simplicity
- Use LINQ when performance matters and the dataset is large
-
Read the Excel sheet
-
Use Excel Application Scope → Read Range into a
DataTable(e.g.,dt). -
Filter rows
-
Use Assign activity:
dt = dt.AsEnumerable().Where(Function(row) row(“D”).ToString <> “2”).CopyToDataTable() -
This keeps only rows where column D is not 2.
-
Write back to Excel
-
Use Write Range in the same Excel sheet (overwrite it) with the filtered
DataTable.
Read Range to get the sheet into a datatable.
Filter Data Table to keep/remove the necessary rows.
Write Range back to the sheet.
You can’t do this, you’ll get an error when trying to modify the same datatable you’re looping through.
This is wrong. This is what the Filter Data Table activity DOES. It removes the rows you don’t want.
My point is that you have another step after the Filter Data Table activity that says “use those filtered result to remove those rows from the original DataTable” but you don’t do that. The Filter Data Table activity does that. Just designate the same datatable as DT1 and DT2 for the Filter Data Table activity.
