How to reference the previous row in a For Each Row

I have an Excel sheet and I’d like to implement the following logic:

If A2 = “Dog” AND A3=“Cat”
Then, do something…

How would I go about doing this with a FOR EACH ROW loop?

This was my thought, but, its not working:

FOR EACH ROW
READ CELL (“A” + rowcounter.tostring) (say this is A3)
READ CELL (“A” + rowcounter.tostring - 1) (say this is A2)

No matter what I try for A2, I always get a cannot convert “String” to “Double” error.

Do you know what the correct way to reference the previous row would be?

Thanks!

Hi @SentientPizza

You are doing the wrong thing.

If your counter is correct then do as shown below :-
(“A”+(rowcounter-1).ToString)

This will not give you error the one you are saying

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

3 Likes

Perfect, thanks!

HI @SentientPizza

You are Welcome :blush:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.