I want to subtract values from two columns in an Excel file, and write the results to three different output Excel files depending on the results of the subtraction: negative, positive or zero.
I have created a ‘Read Range’ activity to read the original Excel file, ‘For each row’ to iterate through the rows and then an ‘If’ control where in condition I wrote something like: cint(row(1)) - cint(row(2)) < 0 then ‘Write Range’ activity to write to a new Excel file with the original Excel file as an input (to get the file with only those with row(2) is smaller than row(1)) . I get the original file generated with no change. Any idea? Thanks.
Buddy @Jasu
Welcome back to UiPath community buddy
Well for this case if you use write range you will get the same table without any change…rather we can create three datatables by using build datatable activity…like out_dt1, out_dt2, out_dt3
All these three tables must have all the columns as string and same no. Of columns as in first excel output datatable and the order of columns must be similar as well …
– then one you have done validation with a if condition, you can use add data row to add that current row from for each row loop to the respective table based on the condition you have madr in the if condition like positive, negative or equal to zero…
– in add data row pass the input as arrayrow like {row(0),row(1),row(2),row(3)}
I have given four values considering like there are four columns in all the table…
Similarly you can use add datarow in each part of if condition based on the validation like either THEN or ELSE part of if condition…
Thats all buddy you are done…
Kindly try this and let know whether this works or not buddy
Cheers @Jasu
A question related to this: I don’t need to write anything to Excel if a condition is not fulfilled. For example, now if the condition cint(row(1)) - cint(row(2)) < 0 is not met, a new Excel file is generated but with no data. How to NOT write/generate any Excel output if a condition is not met?
Buddy remove the activity that enters data to the excel like write range or write cell in ELSE part of the if condiion @Jasu so that it wont enter any data to the excel if the condition gets failed
Cheers @Jasu
buddy where you are getting the value for DT1 buddy
you did have read the excel with read range activity buddy
so the row count in DT1 will be zero only buddy
thats why going to THEN part of if condition buddy
Kindly use read range activity to read the file and get the output variable from that activity as DT1 and pass here buddy
or
if you have datatable ready, with you even before read range activity into a excel, check whether it has any rows in it buddy
Cheers @Jasu