[英]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.