Deleteing the whole row if ( condition)


#1

Hello All,
I have a quick question to the community, Is there a way for a robot to delete an entire row - horizontal
{ if the value of the first column is null ( empty }
I do see a remove data row in activity but need some guidance.
Thank you ! :slight_smile:


#2

The best way is to Read Range then filter your datatable to the rows that you would like to output or process.

Let’s assume your datatable is called dt1, and there are various methods to filter your table but I normally use the .Where with either .ToArray or .CopyToDataTable.

dt1.AsEnumerable.Where(Function(row) row(0).ToString.Trim<>"").CopyToDataTable

The above will return your table where the first column is not empty.

Alternatively, you can set the rows to an array and keep all rows intact in your original table by using .ToArray instead of .CopyToDataTable. That is, if you want to process and update certain rows and not remove the others. (You can also run the .ToArray through a For each to Remove Row or do other things to the rows that you filter)

The second part to this is when you Write Range your table to an existing excel it will keep extra rows, so you must either write to a new file or empty the spreadsheet before writing the table back. You can empty the spreadsheet by using “Clear All” in Excel menu.

The alt-combination to select all and Clear all, would be something like this:
TypeInto "[d(ctrl)]a[u(ctrl)][k(alt)]hea"

I hope this in some way was helpful.

Regards.


#3

Hi @sherpa24,

DataTableName=DataTable.Select("ColumName <> "").CopyToDataTable()

Refer the below post

Regards,
Arivu


#4

Hello : I want to delete the rows from row number 43(Thats not fixed) to till bottom of green box.
i have tried to Remove row by filtering the datatble with 0 value but its not deleting the row.

PFA file for more understaing.

test (2).xlsx (213.9 KB)