Excel dyanmic

hello guys,
see above image, actually i want to extract last two row from this sheet and save in another sheet.
and it will be dynamic so that when i added new row below after that i get same output like row 10, and 11

Hi @Madhuri_kushwaha1

Read Range 
newDataTable = yourDataTable.AsEnumerable().Skip(Math.Max(0, yourDataTable.Rows.Count - 2)).CopyToDataTable()
Write Range

Hi @Madhuri_kushwaha1

Try this

dt_Input.AsEnumerable().Skip(dt_Input.Rows.Count - 2).Take(2).CopyToDataTable()

Input:
image

Output:
image

please show me the variable name

Skip(dt_Input.Rows.Count - 2).Take(2)

please explain this

@Madhuri_kushwaha1

.Skip(dtInput.Rows.Count - 2): Skips the rows before the last two rows.
.Take(2): Takes the next two rows after skipping.

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