简体   繁体   English

在VBA中使用Vlookup()

[英]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? 如何将Vlookup()值写入当前工作表单元格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

If you just want to enter the VLookup formula into T1 如果您只想在T1中输入VLookup公式

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

Otherwise, if you want to calculate the VLookup and then just enter the result... 否则,如果要计算VLookup,然后输入结果...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM