How to delete last 2 rows in Excel sheet

Hi, I need to delete last 2 rows in an excel, but row counts will be dynamic.
I have a code Dt.rows.count -1 which delete only last row, any other one line syntax which can delete last 2 rows ? any idea

Hello.

You can create a variable with the number of lines you want to delete.
You put a while with the limit of this variable.
you use the delete row activity with Dt.rows.count -1 ie for example. You have 5 lines
The first time it executes, it erases the last line (5)
The dt now has 4 lines.
On the next iteration of the while, delete line 4.

Hug

when a datatable is in place and reflecting the data rows count from excel you can do following

Excel Application Scope

  • Inser/Delete Rows Activity
    grafik

On datatable level we can do:
Assign Activity
dtCleansed = dtOrigin.AsEnumerable.Take(dtOrigin.Rows.Count - 2).CopyToDataTable

1 Like

Thank you, it worked

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