I am rather new to VBA and I am having trouble with a VLOOKUP code.
I have 3 sheets. Sheet2 (Supplier) contains the part number & supplier, Sheet 3 (Cost) contains the part number & cost. Sheet1 (Part Numbers) contains a standard part number list. The data in Sheets2 and 3 are updated regularly. I want the VBA to look for the part number (Sheet1.ColumnA) in the supplier list (Sheet2.ColumnA) and paste the supplier name (Sheet2.ColumnC) into Sheet1.ColumnB. Once I figure out how to do this I will then modify the code to do similar with the cost and put it in Sheet1.ColumnC.
Here's what I have so far:
Sub Lookup()
Application.ScreenUpdating = False
Dim Lr As Integer
Lr = Worksheets("Part Numbers").Cells(Rows.Count, 1).End(xlUp).Row ' last row
For i = 1 To Lr ' last row
Worksheets("Part Numbers").Cells(i + 1, 2) = "=VLOOKUP(RC[-1],'Supplier'!A:C,3,0)"
If i = "" Then Exit For
Next i
End Sub
When I execute this code the Sheet1.ColumnB populates (Taken from cell A)
"=VLOOKUP(A2,'Supplier'!A:B:B,3,0)"
Can anyone tell me Why is it showing A:B:B when I enter A:C?
If i = "" Then Exit For
? Seems like it will never do anything. The condition should never come back true. – Mark Balhoff