Compare 2 cells in each row and do something


im trying to implement the following:
I have an Excel File with 2 columns of information (only numbers).
I want to compare the numbers of every row and, depending if number 1 oder number 2 is greater, substract them or add them in a 3rd column (that I still have to add).

How can I do this with a variable that goes “from row to row”, so that I dont have to do an if check for every row on its own?

My basic take so far - to understand what I mean:

Any tips are welcomed!

Best regards

1 Like


Welcome to uipath forum

Hope the below steps would help you resolve this

  1. Use a excel application scope and pass the file path of the excel as input

  2. Inside the scope use a read range activity and get the output as dt

  3. Now use a FOR EACH ROW activity and pass the variable dt as input

  4. Inside the loop use a IF condition like thi

Convert.ToInt32(CurrentRow(0).ToString) > Comvert.ToInt32(CurrentRow(1).ToString)

If this is true then it goes to THEN block where use a assign activity like this

CurrentRow(2) = Convert.ToInt32(CurrentRow(0).ToString) - Convert.ToInt32(CurrentRow(1).ToString)

Or if it’s false then it goes to ELSE block where use a assign activity like

CurrentRow(2) = Convert.ToInt32(CurrentRow(0).ToString) + Convert.ToInt32(CurrentRow(1).ToString)

  1. Then after this for each row use a write range activity and pass the variable dt as input and enable ADD HEADERS property

Cheers @Zer4x


For example, workflow will be the following.


Hi, thanks for your quick answer.

If I try this, I get “CurrentRow is not declared as a variable” message.
I also tried “row” as it is stated in the foreach row block.

As which kind of variable do I need to declare CurrentRow?

Also, can you explain why those Conversions are necessary? since the rows are already only numbers (except the first one, the header)

Best regards

1 Like


It depends on your for each row activity
If you have row as variable name in for each row activity then we can mention as row(0).ToString

If the for each row loop has CurrentRow as variable then we can mention as

And we need to convert the values to int32 as when we use read range activity it will get all the column with the data in string type only
That’s why

Hope this clarifies your query

Cheers @Zer4x


I have used excel activities to do the comparison between two cells in each row and write cells adjacent to each row based upon the result of the given condition.