Increasing 3 variables in For Next loops

Gtabtr1

New Member
Joined
Feb 15, 2017
Messages
39
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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Gtabtr1

New Member
Joined
Feb 15, 2017
Messages
39
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,114,085
Messages
5,545,873
Members
410,711
Latest member
Josh324
Top