![](/img/trans.png)
[英]Excel VBA - Custom Function; #VALUE error; VLOOKUP on different worksheet
[英]Vlookup worksheet function in VBA (runtime error 9)
我是 VBA 新手,我有以下函数代码:
Function checktype(ByVal modele As String)
Dim srchRange As Range
Dim book1 As Workbook
'Set some Workbook variables:
Set book1 = Workbooks("C:\Users\MZ\Desktop\EPI.xlsx")
Set srchRange = book1.Sheets(1).Range("A1:D800")
'This assumes that the Book2 is Open and you are on the desired active worksheet:
checktype = Application.WorksheetFunction.VLookup(modele, srchRange, 4, False)
End Function
此代码的目的是使用 Vlookup 函数从另一个工作簿中获取某个数字,并将该值返回给函数checktype
。
问题是我收到运行时错误 9。当我单击 Debug 时,以下行会突出显示:
Set book1 = Workbooks("C:\Users\MZ\Desktop\EPI.xlsx")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.