How to add serial numbers in particular column

Hi Guys!!

I have an excel template, in which first i have to count number of rows present in the template after finding the number of rows, i have to update the serial number for each row like 1,2,3,4…

The below attached is my template sample. help me to do this

Thanks in advance :slight_smile:

Initialize an int32 variable counter with value 1, then loop through your datatable and for each row, set the value with column name ‘#’ to the counter.
Increment the counter on each loop.

Finally write the datatable back to the Excel


1 Like

Thanks, but I have a doubt… as a first step i have to count no of rows till subtotal row in excel, based on the no of row count i have to update the serial number. can i do that using the above method

Surely, you can add an “if” condition to check when your counter is equal to the row count, you can use a “break” activity to break out of the “For Each Row in DataTable” activity.


For Each r as Datarow in DT.Asenumerable
Next r

Use This Query in Invoke Code

1 Like

@Nishant_Banka1 I tried its working Thank you :slight_smile:

1 Like


For less code, you can use the currentRow index instead of the counter variable.

1 Like

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