Sr.No AUTO INCREMENT

I have a workflow where I’ve merged multiple Excel sheets into one.

In this merged Excel sheet, there’s a column named ‘Sr.No’ which contains random values and I am getting that by using add data row.

I want to replace the values in the ‘Sr.No’ column with serial numbers starting from 1, incrementing by 1 for each row. How can I accomplish this?

Read range the entire sheet into datatable, then do a for each row in datatable. Assign a variable to index
image

Then inside the for each row, assign CurrentRow(“Sr.No”) = intIndex + 1

@Mayur_N

  1. Use the “Read Range” activity to read the merged Excel sheet into a DataTable. Store the output in a variable, let’s say dtMerged.
  2. Use the “Add Data Column” activity to add a new column named “Serial Number” to dtMerged. Set the DataType to System.Int32.
  3. Use a “For Each Row” activity to iterate through each row in dtMerged.
  4. Inside the loop, use an Assign activity to set the value of the “Serial Number” column for each row. You can use the RowIndex property of the DataRow object to get the current row index.Assign activity:

row(“Serial Number”) = row.Table.Rows.IndexOf(row) + 2

Note: row is the variable representing the current DataRow object.
5. Finally, use the “Write Range” activity to write the updated DataTable back to the Excel file.

Hey @Mayur_N

I have solved your issue, just use a invoke code activity

Dim count As Integer
count=1
io_dt_Input.AsEnumerable().ToList.ForEach(
Sub(x)
x(“Sr.No”)=count
count=count+1
End Sub)

In/Out argument: Input Datatable Variable

Example for your refence:
Input:

Output:

Code:

Attaching .xaml for your refence!
SR_No.Increment.xaml (8.2 KB)

If your issue got resolved then kindly mark this post as Solution. So, that others will get correct solution!

Happy Automation!

Regards,
Ajay Mishra

i am trying many times can you give solutuion