Variable selects last row when in 'For Each Excel Row.. '

Variable selects last row when in 'For Each Excel Row… ’

Hi, I have a list of numbers in a column in Excel Sheet2 and I’m trying to iterate through each row getting the number into a variable that I then use on Sheet1 to filter. However I can’t get the variable to select the first row number, it always selects the last. It has NEVER selected the first. If I delete the last number in the Order column then it will still select the last number.

I have a Select Variable set for Order column below in a For Each Excel Row. I expected it to pick up the first row number 8162235 but it always pick up the last number no matter what the number is or how many rows I have in the column.

Order
8162235
8198249
8193567
8193775
8194023
8194096
8194420
8194947
8194996
8195025
8195090
8195382
8195466

Variable in UiPath StudioX

Result when run. There are 13 numbers before this filter all in the Order column:

Filtered Sheet1

Does anyone have any idea why or what I can do?

Many thanks!
Heidi

@heidi.burnett

from screenshot looks like only assign is present in the for loop…if so…by default only last value will be stored as once the for loop completes the value will be the last one as the last iteration is for last order number

you can to do all your tasks inside the for loop only then for each iteration number will change

cheers

Hmm this is in a Do While loop, the above is the first process. I’ll add the rest of the process in. I think I have already tried this but will try again… Thank you!

@heidi.burnett

Please explain what you are trying to do…as this is how the current one works…

do while one iteration and for loop all iterations always…as it is inside do while…so have only one loop if you need to run both loops only once and use logic accordingly…

as of now…as explained it will always save only last…as you are rewriting from the first

cheers

I added in the Filter in the Do While loop, now no filter is applied to the column on Sheet1

I have a spreadsheet Sheet1 which has a list of orders in Orders column and tracking details in Shipping column. This is one Order to many Shipping lines.

  1. I copy the Orders column to Sheet 2 and delete duplicates.
  2. I then save the first order number from Sheet 2 into a variable to filter Sheet1 Order column
  3. From that one Order I then copy the many Shipping lines to Word
  4. All the lines from the Word doc are then pasted into another application under the Order number.

Numbers 1, 3 and 4 are all working. I just can’t get number 2 to work selecting the first row on Sheet2 in the Orders column.



@heidi.burnett

As per explanation looks like the second use excel needs to be inside the for each row in excel activity and change the reference to excel2 and use it…then for each row it would be filtered and all steps are performed

Cheers

Thank you, I shall try this

1 Like