# Increasing 3 variables in For Next loops

#### Gtabtr1

##### New Member
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:

### Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying

#### Gtabtr1

##### New Member
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

Replies
5
Views
55
Replies
1
Views
69
Replies
3
Views
69
Replies
1
Views
84
Replies
3
Views
57