SmallFries BigGuys
SmallFries BigGuys

Reputation: 171

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

Upvotes: 0

Views: 3199

Answers (1)

Rdster
Rdster

Reputation: 1872

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)

Upvotes: 1

Related Questions