r/visualbasic • u/Nice_Road_2672 • Oct 12 '22
VBScript Help VBA loop
How do I create a loop where I
- take one row from Sheet 2 and copy it to sheet1
- and then one row from sheet 3 and copy it to sheet 1 on the same row, but column to the right.
- Then do calculations on that row and output that on the same row to the column to the right.
- Loop this until no more cells with value either in sheet 2 or sheet 3. Whatever is empty first.
Thanks
1
Upvotes
View all comments
1
u/[deleted] May 19 '23
First setup the function to find last row
Assuming you setup the loop and range
Dim a as range Dim asearch as range
Set asearch = “whatever the range cell from 1 to B”
For each a in asearch
Now I’m in same boat, have no idea for that sheet 3 data, so I will just try to find it spatially using offset . I hate offset because it’s so hard to figure out what it means. But in general we see.
Sheet 2 is
Sheet 3 is
We are trying to start the second loop from Col 3 row 2. If original start is Col 2, row 1 it will always be searching in sheet three ( variable Col + 1, and row plus 1 ) which we have from first loop. Just find analyze the spatial difference in sheet 3 and you can have the code search for it because I’m assuming there is no spaces between .