How can i get the row index?

My question is about how can i get the row index for use it as a variable or put it into a variable.

Thanks everybody.


Hi @sermuolo

You can use this :

[your DataTable variable].Rows.IndexOf(row)

which [row] is defined as the row of [your DataTable variable] in [for each row ] activity .



Its not working on mine, It overlaps its value in one index in excel


I wrote a sample for you ,so you can compare it with your code.
Or you can upload your code so I can check it. (9.0 KB)

1 Like

Employees.xls (19 KB)
RecToExc.xaml (38.5 KB)

I used ExpenseIt (Uipath Dummy generated app).


This is probably because the for each row loop writing the inputDT is nested inside the other For Each Row loop. You could do this a whole lot simpler, you don’t even need to have a second datatable. Just add the new column to the table before the for each row loop, and write the value into it (you can do this directly inside the output field of the Get Text activity, don’t even need the variable). Then you can write the datatable back into the excel.

I quickly made some changes to your xaml, this should work. Let me know if you have questions :slight_smile:

RecToExc.xaml (33.4 KB)


Thank you so much

1 Like

Check lookup data table activity.


I just did what u said about [DT variable].row.indexOf(row)
i did a test and for some reason if I didnt add 1 to the index it printed (in write cell) the data to the whole page of Excel (from 1 to 104000…)
if i add 1 to the index it will start from the first row (even if its a heading)
and if i add 2 to the index it will start from the second row (first row without heading)
can u please explain how it works?

thanks in advance!!

This is because the datatable index starts from zero (0) for the first item.
item(0), (1), (2), (3)…