Excel Automaion Scenario Based

Hi ,

I have an excel use case doubt scenario, which I recently faced in the prod environment, that is: Excel has two sheets, In sheet 1 consists of 50 rows of data available, and In sheet 2 consists of 50 rows of the same data available. Now I want to copy the last 5 rows of data from sheet 2 and paste them into the first five rows of sheet 1 ? How can we do this?

Please clarify.

Thanks & Regards,

Hi @Harsha_S1 ,

Can you try this

DT1 for Sheet1
DT2 for Sheet2

Get last 5 rows of sheet2

DT3 = DT2.AsEnumerable.Reverse().Take(5).CopyToDataTable

Merge DT1 and DT3.

I have attached xmal for your reference

Excel.xaml (6.6 KB)
Excel.xlsx (10.5 KB)

You can count total# of rows in sheet2, after that -5 from total and store into a DT.
Now Read that DT and using write range to sheet1, it will come into first 5 rows.

Hope that helps.

1 Like

Thank you Umadevi_Sanjeevi for your effort.

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