I'm trying to write a code to use vlookup
where the reference is another file. The reference table is from cell a2
to a300
. The lookup value is from cell G2
to end of column. The vlookup
is to be done in column AA
.
I found the code below on one of the solutions on this website, but have no idea how to change it to suit my file.
Sub SBEPlannerAdder()
Dim rw As Long, x As Range
Dim extwbk As Workbook, twb As Workbook
Set twb = Workbooks.Open("C:\Users\OUROBOROS\Desktop\30-5-19\vba\VBA\Gents_SW_May'19.xlsb")
Set extwbk = Workbooks.Open("C:\Users\OUROBOROS\Desktop\30-5-19\vba\VBA\1st phase stores.xlsx")
Set x = extwbk.Worksheets("Sheet1").Range("A1:C300")
For rw = 2 To twb.Sheets("Sheet1").Cells(Rows.Count, 25).End(xlUp).Row
twb.Sheets("Sheet1").Cells(rw, 2) = Application.VLookup(twb.Sheets("Sheet1").Cells(rw, 1).Value2, x, 2, False)
Next rw
extwbk.Close savechanges:=False
End Sub