How to Increment Sr.Number in Excel

I want to increment Sr.No in my excel file. I am using variable = variable +1 in Assign activity but it is adding next number into variable value and not incrementing.


this activity gives me below output

But actually I want to increment this number as 3743 and update into excel

Hi @nilesh.mahajan,

Why does it not work?

Because you first converted backrow variable to a String type Row_Count.Rows(Row_Count.Rows.Count-1)(0).ToString . Therefore, adding 1 will give you either an error or if using GenericValue type add it to the end of the string.

  • I also think there is a nested for loop there so you get “11” in the message box.
  • I am suspecting you are using GenericValue argument type for your backrow variable. Usually when you try to add an Int to a String, UiPath will give you a error notification as below. This notification does not show up when argument type is GenericValue. I suggest you do not use GenericValue types when using loops.

Solution: backrow = Convert.ToInt32(Row_Count.Rows(Row_Count.Rows.Count-1)(0).ToString)
backrow here is of Int32 argument type.

This will treat 3742 as an Int type and will allow increment operation.

Here is a workflow for your reference: IncrementValue.xaml (6.4 KB)

1 Like

thnx for solution. Its work for me correctly.

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