Increasing 3 variables in For Next loops

Gtabtr1

New Member
Joined
Feb 15, 2017
Messages
33
Hello
I need to loop through a range from column 27 through 40 and row 3 through 17,694 (dimmed drow) performing a vlookup in every cell using a lookup table with 16 columns.

p=3 'row
tc =3 'column index in vlookup
v = 27 'destination column
For tc = tc to 16
For v = v to 40
p = 3
For p = p to drow
Cells(p, v).Value = Application.VLookup(Cells(p, 1), Workbooks(Book21Name).Worksheets("Sheet").Range("E2:T" & erow), tc, False)
Next p
Next v
Next tc

It works on all rows of column 27 (variable v). but I need the destination column(v) and the column.index (tc) in the vlookup formula to change at the same time.

Help?
 
Last edited:

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Gtabtr1

New Member
Joined
Feb 15, 2017
Messages
33
Thank you all but I figured it out.
p = 3
tc = 2
v = 27

For v = v To 40
p = 3
tc = tc + 1
For p = p To drow
Cells(p, v).Value = Application.VLookup(Cells(p, 1), Workbooks(Book21Name).Worksheets("Sheet").Range("E2:T" & erow), tc, False)
Next p
Next v

It may not be as eloquent as others but it works :)
 

Watch MrExcel Video

Forum statistics

Threads
1,109,456
Messages
5,528,864
Members
409,842
Latest member
mfernandezcean
Top