Search code examples
vbaexcelvlookupexcel-2013worksheet-function

Use Vlookup() With VBA


I keep getting an error of

Object Required

running my syntax. This is the syntax that I have, but it is not successful. How can I write the Vlookup() value to my current worksheet cell T1?

Public Sub Test()
  Dim dblInfo
  dblInfo = Application.WorksheetFunction.VLookup("A2", Sheet1.Range("A2:F171"), 4, False)
  Range("T1").Select
  ActiveCell.FormulaR1C1 = dblInfo
End Sub

Solution

  • If you just want to enter the VLookup formula into T1

    Range("T1") = "=VLookup(A2, Sheetname!A2:F171, 4, False)"
    

    Otherwise, if you want to calculate the VLookup and then just enter the result...

    Range("T1") = Application.WorksheetFunction.VLookup([A2], Sheetname.Range("A2:F171"), 4, False)