Reading columns from an excel file, then compare them using an IF statement

Hello, I am a beginner using Uipath and I am looking for some help. I have two columns in Excel column A and B. I want compare each row in A with B using an IF statement. IF the number in A > B then subtract Else multiply, and have the answer in the Result column.

Column A = 2 Column B = 3 Results = 6

Because column A is less than B we multiply.

Column A = 4 Column B = 2 Result = 2

Because column A is grater than B we subtract. How would I create this state in the IF activity?

Hi Greg,

First you need to use Read Range activity to get data from excel and store it as DataTable variable.
Then use For Each Row to loop into row and in looping you use IF statement

If (Int32.parse(row(“A”).ToString) > Int32.parse(row(“B”).ToString))
Then -> Result = Int32.parse(row(“A”).ToString) - Int32.parse(row(“B”).ToString)
Else -> Result = Int32.parse(row(“A”).ToString) * Int32.parse(row(“B”).ToString)

(Assuming your column name is “A” and “B”)

To compare value or calculate value as integer or decimal from data from excel, you need to convert it to data type as you want. Above example is to convert it to Integer(32) data type.

Hope this helps you !

1 Like

Thank you for replying, I did what you suggested and I made one change, From A to ColA and ColB. However, I getting this error.


If you use Write Line activity, you need to convert content to String data type

Example : (Int32.parse(row(“A”).ToString) - Int32.parse(row(“B”).ToString)).ToString