Macro to set a vlookup

northern225

New Member
Joined
Sep 11, 2012
Messages
11
Hello,

I am looking for a macro to insert a vlookup in row 2 for every 5th column? Current vlookup forumla: vlookup(E1,vlookup!$A:$B,2,0)

Any help would be appreciated!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How far out should it go (which column does it stop at)?
 
Upvote 0
Let's say that you wanted it to go out to column 100 (so you would have 20 VLOOKUP formulas). Then the macro might look something like this:

Code:
Sub VlookupMacro()

    Dim myCol As Long
    
    For myCol = 5 To 100 Step 5
        Cells(2, myCol).FormulaR1C1 = "=VLOOKUP(R[-1]C,vlookup!C1:C2,2,0)"
    Next myCol
    
End Sub
 
Upvote 0
It looks like column ALQ is column number 1005. So just replace the loop row in my previous code to:
Code:
For myCol = 5 To 1005 Step 5
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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