Hi all
I’m having trouble with the syntax to refer to a named range in ThisWorkbook when attempting a VLOOKUP from another (newly created, ActiveWorkbook) workbook.
Specifically I receive a Compile Error: object required message on the Set myVLookupResult line.
Any help is much appreciated.
Thanks & regards
Mark
I’m having trouble with the syntax to refer to a named range in ThisWorkbook when attempting a VLOOKUP from another (newly created, ActiveWorkbook) workbook.
Specifically I receive a Compile Error: object required message on the Set myVLookupResult line.
Any help is much appreciated.
Thanks & regards
Mark
Code:
Sub Lookup_Consumables()
Dim myLookupValue As Range
Dim myNamedRange As Range
Dim myVLookupResult As Long
Dim book1 As Workbook
Dim book2 As Workbook
Set book1 = ThisWorkbook
Set book2 = ActiveWorkbook
Set myLookupValue = book2.Sheets(2).Cells(3, 1)
Set myNamedRange = book1.Sheets(2).Range("Consumables").Value
Set myVLookupResult = WorksheetFunction.VLookup(myLookupValue, myNamedRange, 3, False)
Dim ws As Worksheet
Dim myRange As Range
Set ws = book2.Sheets(2)
With ws
.Range(Columns(11), Columns(12)).ClearContents
.Range("L3:L" & lr).Formula = myVLookupResult
End With
End Sub