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:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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 :)
 
Upvote 0

Forum statistics

Threads
1,215,368
Messages
6,124,520
Members
449,169
Latest member
mm424

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top