下面是我的宏的代码,我在*中的文本上一直有一个错误。
我正在尝试使用一个vlookup,它将看到用另一个按钮选择的随机单词并拉出定义。
在Excel中添加常规vlookup代码:vlookup
Sub Definition2()
Dim lookupvalue As Variant
Dim lookuprange As Variant
lookupvalue = Sheet2.Range("B2").Value
Set lookuprange = Sheet1.Range("A2:B500")
'- 2: execute vlookup functionwith variables above -'
vresult = Application.VLookup(lookupvalue, lookuprange, 2, False)
Range("J3").Value = vresult
End Sub发布于 2018-04-02 22:08:44
更新应答
而不是使用行指定范围,而是将vlookuprange设置为整个列。
第一答案
不能“设置”声明为字符串的变量,因为它不是对象
Sub Definition2()
Dim lookupvalue As String
Dim lookuprange As Range
Dim lookupcolnum As Single
lookupvalue = Sheet2.Range("B3").Value
Set lookuprange = Sheet1.Range("A:B")
'- 2: execute vlookup functionwith variables above -'
vresult = Application.VLookup(lookupvalue, lookuprange, 2, False)
Range("J3").Value = vresult
End Subhttps://stackoverflow.com/questions/49619233
复制相似问题