How to copy mutiple rows into different excel sheets

The task is header row and first row ,header row and second row likewise consecutive rows i have to copy from one sheet to other sheets. How to do this activity.

when iterating over the datatable rows with
For each row in Datatable Activity | currentRow in YourDataTableVar

you can quickly build the datatable by:
new DataRow(){currentRow}.CopyToDataTable and can use it for writing out to a Worksheet with write range (addHeaders should be enabeld)

can you please send the code

could look like this:

dtData - the origin datatable
idx - the index output from the for each activity



can you check the below code (157.0 KB)


what is the purpose of dt.clone
actual purpose and where we use that?

The code is bit confused can you please put the simpler code in an understandable way

Hi @anjani_priya

Clone is used to add the headers from Previous Table to Your New assigned DataTable
For Ex : Read Range - OutPut is Dt_1
In assign activity take a variable of Datatype - Dt_2 = Dt_1.clone (It will add all the headers of Dt_1 to Dt_2)


clone gives you the all the columns of the main datatable

it is composed by essentials. What in detail is unclear?


is the code which i have shared is working fine or not

let me know

ok Thankyou
and can you please explain how to add different rows of one sheets to different excel sheets like first row to sheet1,second row to sheet2 likewise

Its working but its just adding only last row,how to customize the rows and add diff rows in diff sheets.

I didnt understand the code.



index is the variable of for each row in datatable activity

can check it once working for me fine

for essentials we recommend the UiPath Academy for learning

Lets assume a datatable with 2 rows. When splitting it we want to have e.g. Sheetnames:
Sheet_0, Sheet_1

This we did by using the index from the for each row in datatable:

when having a single datarow, but a datatable containing this row is needed (we do for the write range) then we create a DataRow Array, placing the datarow in it and use the CopyToDataTable method to transform it into a datatable

more clear now?

how can I specify the particular row in the code?I need only particular now in each sheet,how should I specify?


you can use if

condition current(“ColumnName”).equals(“Passavalue”) or



use the add datarow activity and write range activity

In the condition mention the row values of any of the column so that it will skip


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