I am trying to write a vlookup code that uses the lookups tab as the array (A:B) and the revenue tab where the vlookup is in cell Y2. I need it to fill all the way through column Y.
Sub VLOOKUP()
Dim LookupsLastRow As Long
Dim RevenueLastRow As Long
Dim LookupsSheet As Worksheet
Dim RevenueSheet As Worksheet
'What are the names of our worksheets?
Set LookupsSheet = Worksheets("Lookups")
Set RevenueSheet = Worksheets("Revenue")
'Determine last row of source
With LookupsSheet
LookupsLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With RevenueSheet
'Determine last row in col P
RevenueLastRow = .Cells(.Rows.Count, "X").End(xlUp).Row
'Apply our formula
.Range("Y2:Y" & RevenueLastRow).Formula = _
"=VLOOKUP(V2,"Lookups"!$A$2:$B$" & LookupsLastRow & ",2,0)"
End With
End Sub