![](/img/trans.png)
[英]Error 1004 - Vlookup in vba - Unable to get the Vlookup property of the WorksheetFunction class
[英]Excel VBA: Error 1004 WorkSheetFunction 'Unable to get Vlookup property"
試圖在Excel 2010中快速編寫一個VBA
我的困難在於公式。
Sub Metrics123()
Dim x As Integer
x = Application.WorksheetFunction.VLookup("Test", "A7:D9", 3, False)
Range("A1").Value = x
End Sub
當我運行這個時,我點擊了error 1004: 'Unable to get the Vlookup Property of the WorksheetFunction
任何指針贊賞!
兩種方式適合你。
1)使用.Formula
屬性:
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
.Formula = "=VLOOKUP(""Justin"",A7:D9,3,FALSE)"
.Value = .Value
End With
其中.Value = .Value
用它的結果重寫公式
2)使用帶有Range("A7:D9")
Application.VLookup
代替"A7:D9"
:
Dim x
With ThisWorkbook.Worksheets("Sheet1")
x = Application.VLookup("Justin", .Range("A7:D9"), 3, False)
Range("A1").Value = x
End With
注意, x
應該是Variant
,因為如果沒有找到, Application.VLookup
將返回Error 2042
( Error 2042
#N/A
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.