How can i get last row and print in first row

Hello,
i am writing some data in excel and one it is done i need to get last row of the excel and ned only that data should be remain in excel i first row like below
current data in excel -

expected output -

how can i achieve this?
any filter i ned to use?

Hi @Mathkar_kunal,

Read Range into dtData.

Get last row:

lastIndex = dtData.Rows.Count - 1

Create new DataTable and keep only last row:

dtResult = dtData.Clone
dtResult.ImportRow(dtData.Rows(lastIndex))

Write Range back to Excel (overwrite sheet).

ok,

so here
dtResult = dtData.Clone
dtResult.ImportRow(dtData.Rows(lastIndex))

dt resut i need to do in assign
what about dtResult.ImportRow(dtData.Rows(lastIndex)) ??

@Mathkar_kunal

  1. Use Find First/Last Data Row activity to get last row.
  2. Just create another sheet in the same file and write data headers from the original sheet
  3. Now write the last row data by using last row identified by first step to the new sheet.
  4. Delete older sheet

ok have some questions regarding activity

wht i need to write in range as my range varies sometimes it will be A1:B5 or sometimes A1:B10 with headers.
have two column as showed i my queery.

what i need to fill in remainig fields of this activity?

and how output will besaved? and how it will write in next sheet if i create?

Just pass the sheet range like Excel.Sheet("Sheet1")

Use Read range activity to get data from range “A”+intLastRowIndex.ToString+“:B”+intLastRowIndex.ToString

Then write this range in the new sheet.