I would like to pull data from a closed worksheet using GetOpenFileName and VLOOKUP, but I am new to VBA and unfamiliar with the syntax.
I keep hitting an "Automation error" or "Object error" that doesn't specify what is wrong. I believe my range arg in VLOOKUP is incorrect but am not sure what it should be. Can anyone help me please?
Sub GetAmazonInventory()
Dim wbk As Workbook
Set wbk = Workbooks.Open(FileName:=Application.GetOpenFilename, ReadOnly:=True)
wbk.Activate
Dim shtName As String
shtName = wbk.Worksheets(1).Name
Dim sh As Worksheet
Set sh = wbk.Worksheets(shtName)
wbk.Close
ActiveCell.Value = Application.IfError(Application.VLookup(ActiveCell.Offset(0, -12), sh.Range("A2:F900"), 5, False), 20)
End Sub