Dynamic Vlook up

hanz753

Board Regular
Joined
Aug 9, 2017
Messages
53


Hello,





I need a dynamic vlookup code in Column N sheet “Aug”, thelookup is in column B sheet “Aug” and the table is in sheet “Mapping”. I needthe vlookup to pull column 3.





=Vlookup(worksheets(“Aug”).range(B),worksheets(“Mapping”).range(“C:E”),3,False.





This is the formula I need to write in vba.





Kr


Hanz
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The best way to get a formula in VBA is to write it on the spreadsheet first. Get it to work and then...

Turn on the macro recorder >> select the cell with the formula >> hit the tab key >> turn off the recorder

Now look in the VBE for what was recorded
 
Upvote 0
Great, I've got the code now, but how do I drag the formula down to bottom of the tablein VBA
thank you for your support
 
Upvote 0
As an example...

Code:
Sub Macro1()
    Range("J1:J37").FormulaR1C1 = "=VLOOKUP(RC[-1],C[-9]:C[-7],3,0)"
End Sub
 
Upvote 0
This is what I managed to get..

Range("O2").Select
Worksheets("FI Aug").Range("O2:O2000").FormulaR1C1 = "=VLOOKUP(C[-13],'FI Mapping'!C[-12]:C[-10],3,0)"

Range("N2").Select
Worksheets("FI Aug").Range("N2:N2000").FormulaR1C1 = "=VLOOKUP(C[-10],'FI Mapping'!C[-11]:C[-9],3,0)"
Range("O2").Select

I had to use "O2000" and "N2000" because I need the formula to drag to the bottom, by doing this it exeeds the table. I need the fomula to stop at the bottom of my data set.
 
Upvote 0
Then you need to establish the end of that data set. Let's say you know column B is the end of the data set.

Code:
Sub Macro1()
    Dim LR As Long
    LR = Range("B" & Rows.Count).End(xlUp).Row
    Range("J1:J" & LR).FormulaR1C1 = "=VLOOKUP(RC[-1],C[-9]:C[-7],3,0)"
End Sub
 
Upvote 0
Works Perfectly, thank you.

The next step would be to copy paste columns A:M into a separate sheet depending on the outcome of the vlookup.

If in column (N or O) if we have the text "Mail" I need all the data to copy and pasted into a separate sheet

Thank you
 
Upvote 0
Since the initial question has been asked and answered, please start a new thread for this new question.
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,304
Members
448,564
Latest member
ED38

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