Vlookup

rubinda

New Member
Joined
Jun 26, 2018
Messages
36
I am trying to lookup the value in column I, in worksheet "QA Hold", and paste the value from the lookup table in worksheet “Master Part Numbers” A2:B1000, column B, and paste in column J in worksheet “QA Hold”.

If I were doing a formula, it would look like this: =VLOOKUP(I2,'Master Part Numbers'!A:B,2,FALSE)

I want to do this without the formula, just code, and I would like to start pasting in J2 and loop.

I have the following code, but it returns “#NAME?”. Can you please assist? Hoping I am not too far off.

Sub VlookupPartDesc()
Dim lLastRow As Long

With Sheets("QA Hold")
lLastRow = .Cells(.Rows.Count, "I").End(xlUp).Row
With .Range("J2:J" & lLastRow)
.FormulaR1C1 = "=VLOOKUP(I2,'Master Part Numbers'!A2:B1000,2,FALSE)"
.Value = .Value
End With
End With

End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Change this...
.FormulaR1C1 = "=VLOOKUP(I2,'Master Part Numbers'!A2:B1000,2,FALSE)"

To this...
.Formula = "=VLOOKUP(I2,'Master Part Numbers'!$A$2:$B$1000,2,FALSE)"
 
Last edited:
Upvote 0
Perfect. Thank you! How d get it to automatically enter the data in column J without having to run the macro?
 
Upvote 0
Relative references entered to a range from VBA are increased just as they would be if you applied the fill or copy/paste.
 
Upvote 0
I don't know what that means. I am fairly new to this. Does that mean I need to do something different for the data to automatically populate?
 
Upvote 0
I thought you were asking why the references changed automatically, but it sounds like you want an event change code to fill the vlookup formula without having to run the macro, correct?
 
Upvote 0
Maybe:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = Cells(Rows.Count, "I").End(xlUp).Row and Target.Column = 9 then
Call VlookupPartDesc
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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