Write range every two rows

Is there any way to use the Write Range activity, in a for each activity, to write a datatable (2 rows) and then for the next datatable write the other 2 rows under the first?
For example, the Write Range activity pastes the datatable at C9, loops, next paste at C11, C13, C15 and so on

Either that, or if there is any way to collect all the data in a datatable and then paste all of it (kind of like append range) but on a specific cell? Or is it only doable to collect that amount of data in the same datatable through data scraping?

@Robert_Wennberg You can Merge Datatables each time :sweat_smile:

1 Like


Thanks for the reply!
I will look into it and see if I can solve the problem. I am fairly new to UiPath and RPA in general so I am not so good at it!
I will try your advice immediately, thank you


I have added the merge table activity but every time I run it I just get the error:
Merge Data Table: Object reference not set to an instance of an object.

What can I do to solve this issue? I have added the source as the datatable I am reading the range from and destination as a new datatable to later be used in a write range activity in another excel workbook.

Hi @Robert_Wennberg,

You can either use read range and then use myvariable.Rows.Count.string to count the number of rows of the range then just sum that range a + 2 and have write from there. Remember that the Write Range Activity you can put variables in there. Also you can just use a for each row then add the rows then once finished add 2 empty rows using the add row and just entering “” for example. Then loop again to keep adding more rows. Add row adds the rows at the bottom of the datatable. Once finished then just use write range to write the datatable to and excel or csv if you prefer but that´s another activity for csv.

1 Like


Thank you for the quick response and detailed explanation!
However, stupid as I am I am not sure how I would be able to accomplish that…
I am using a for each row where I grab the data from each excel file and want to extract all of the files to another excel file, but it is just writing the latest one. I am not sure how to two empty rows at the end of the for each.
Sorry for being a bother. I will attach my xaml and also a dummy picture to show where I am at.
Thank you for your help

DBExtract.xaml (14.6 KB)

Also worth noting that I want to put all the data from cell C9 in the new excel workbook, so a append range would not do the trick, I think…

Finally understood how to use Merge Datatables.
So for people who are not the brightest as me this is what I did:
Merge Datatable source: DT1
Merge Datatable destination: DT2

Make sure the DT2’s default in the Variables list is “New System.Data.DataTable”.

That did the trick for me at least

Thanks for your help @supermanPunch

1 Like

@Robert_Wennberg Good Job, Keep Learning More :smile:

1 Like

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