How to Delete the Datarow from excel using For Each row

Hi I want to delete record in excel while looping through.

i want to delete the row if the user is Inactive and transfer it to another Sheet.
can someone help me?

@Vincent_Nuestro ,

Read the sheet as a datatable and filter the data using Filter datatable activity. Then write the filtered datatable in a new sheet.

hi @sarathi125 ,

can you share me a workflow?

@Vincent_Nuestro - Is it ok for filtering and writing in a new sheet??

Hi @prasath17 yes,
but it must remove from original sheet(Sheet 1)

@Vincent_Nuestro - Please check this… (43.1 KB)


As an alternate: you can easily filter and write it to the different sheet and use BalaReve delete sheet activity to delete the sheet and then write your filtered result.

hi sir @prasath17 can you share me the screenshot instead?
i cant open the file due to UIpath version

@Vincent_Nuestro -

Build Datatable

Add to Collection

hi @prasath17

@Vincent_Nuestro - please show your workflow screenshot ???

@Vincent_Nuestro - Second For Each should be outside of the first for each…

Hi @prasath17 i already placed it outside the for each row and it successfully executed,
but the problem is, the data that i wanted to remove from the excel is still in there.

@Vincent_Nuestro - You have to understand what is going on here…

You are reading from the sheet as datatable and removing the row from it. it means you are not removing the row from sheet.

So first write the output to the new sheet and check it … if you have to right result then Use Balareva activity to remove the sheet.

should I add write range activity first?

@Vincent_Nuestro - Yes…

I have sent you a personal message, please check it and respond…

Hi @prasath17 as a result
It write the other data status to new Sheet(Sheet 2)

but the (Graduated) status still in Sheet 1 and nothing happens

You can use Filter data table activity to remove the row y you use for each only or you need to do using for each use data row or save that in another sheet expect that row and delete that sheet simple

Chethan P


You could use LINQ here with no For Each activities:

  1. Data table of Inactive rows:

yourDataTable.AsEnumerable().Where(Function (row) row(“Status”).ToString = “Inactive”).CopyToDataTable()

Use a write range sheet2

  1. Data table of other rows:

yourDataTable.AsEnumerable().Where(Function (row) row(“Status”).ToString <> “Inactive”).CopyToDataTable()

Use a write range sheet1

Hi @Vincent_Nuestro ,

This should do the trick as you are using an older version of UiPath: (12.3 KB)

Hope that helps !

Thanks & Regards,

1 Like