Automated Calculations in Uipath for a Excel worksheet depending on a condition

Hi there,

I have a Excelfile with two Columns, with I have to compare. It looks like this:

First Column Second Column Results
2 7
8 5

I need to compare the First Column (2) with the Second Column (7).

If First C. > Second C. i need to subtract them (First C. - Second C.)
Otherwise, I have to multiply them (First C. * Second C.).
The Result needs to go in the “Result” column.

I struggle to find a way, that calculates each row with the specified.

I used a Excel Application Scope to read the Columns, used the “Get range Table” to get a string for First C. and Second C.
With the “Flow Decision”, I compared them (First C. > Second C.).
Then, I used in an other Excel Application Scope the “For each row”-function to assign the rows and tried to write the the result back into excel with “Write Cell”.

Can someone help me please?

Thanks in advance,
Tryagain :slight_smile:


Hi @Tryagain
Kindly follow the below steps that could help you solve this issue buddy

-use excel application scope and pass the file path as input
-use read range activity and get the output as datatable as output named outdt
–use a for each row loop and pass the above variable as input and inside the for each row loop use a if condition like this
Convert.ToInt32(row(“FirstColumnname”).ToString.Trim) > Convert.ToInt32(row(“Secondcolumnname”).ToString.Trim)
–if this condition gets satisfied it will go to THEN part of if condition where you can use assign activity to subtract them
row(“ResultsColumnname”)= Convert.ToInt32(row(“FirstColumnname”).ToString.Trim) - Convert.ToInt32(row(“SecondColumnname”).ToString.Trim)

–and if the above condition gets failed it will go to ELSE part where we can multiply the value we want like this
*row(“ResultsColumnname”)= Convert.ToInt32(row(“FirstColumnname”).ToString.Trim)

Thats all buddy
Hope this wuld help you
Kindly try this and let know for any queries or clarification
Cheers @Tryagain


Thank you so much for your help. I now get this error:

Compiler error(s) encountered processing expression “OutDT”.
“Option Strict On” doesn’t alow a convertation from System.Data.DataTable toSystem.Collections.IEnumerable.

I tried to fix it, but then different errors came up. Couldn’t really find an answer… Can you help me again?

Thanks a lot already.