Delete last 6 rows in a specific Table

Hello Everyone,

I am using UiPath StudioX and I need to delete the last 6 rows of a specific table.
Would Appreciate any help.

@Ansari_Mohammed Aslam o alaikum.
Hope so you will be in good health.
Please follow these steps.

I’ll assume your datatable is a variable called dt1.

Use the remove data row activity with the following as inputs in the properties window:
DataTable: dt1
Row: (leave this blank)
RowIndex: dt1.rows.count - 6

This will remove the last row of dt1. The reason why you include the minus 1 after rows.count is because the index of the datatable starts at 0, but counting the rows will start at 1 (e.g. row #1 will be index 0, but the count would start at 1)

You put -6, which won’t delete the last row.

@Ansari_Mohammed the appropriate way to do this is to use the Take function, and take the total number of rows minus 6.

Assign yourDT = yourDT.AsEnumerable().Take(yourDt.Rows.Count - 6).CopyToDataTable()

Hi,

FYI, if you use Windows or CrossPlatform compatibility (not Windows-Legacy), the following will work

  dt = dt.AsEnumerable.SkipLast(6).CopyToDataTable()

image

Regards,

WA AS,

No changes were done to the table. Attaching a screen shot.

I think Paul and Yoichi’s suggestion is whilst using Studio, I am using StudioX.

Hi @Ansari_Mohammed
yes you are right it will delete only one row.
you need to loop over start from dt.Rows.Count-1
till dt.Rows.Count-6
RemoveRows.xaml (12.3 KB)

@Ansari_Mohammed Try this Logic

  1. read input Excel as DTinpur
  2. Assign “CountRow=DTinput.Rows.Count-6” (integer variable type)
  3. use a while loop with the condition CountRow<DTInput.Rows.Count
    3.1 withing loop Assign “CountColumn=0”(integer variable type)

3.2 Use another loop CountColumn<DTInput.Columns.Count
3.2.1 within this loop set assign as Dtinput.Rows(Countrow)(CountColumn)=String.Empty
3.2.2 place assign to increment value CountColumn=CountColumn+1

3.3 place assign in 1st loop as CountRow=CountRow+1
image
image

image

You should still be able to use expressions in StudioX.

Also, the -6 is wrong. That won’t remove the last 6 rows, it will remove the 6th row from the end.

You need to use -1, and do it 6 times.

Tried Paul’s idea and indicated the right data table. Yet keep getting an error message as there is no row at position 6. the position value changed based on data table. Encountered another message due to using Enumearble. was able to work around that by adding an assembly line to .xaml page.

For now have fixed the issue by filtering and deleting the visible rows.
Thanks Everyone.

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