Emi*_*doz 6 excel vba excel-vba
试图在Excel 2010中快速编写一个VBA
我的困难在于公式.
Sub Metrics123()
Dim x As Integer
x = Application.WorksheetFunction.VLookup("Test", "A7:D9", 3, False)
Range("A1").Value = x
End Sub
Run Code Online (Sandbox Code Playgroud)
当我跑这个我打了 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
Run Code Online (Sandbox Code Playgroud)
其中.Value = .Value
用结果重写公式
2)使用Application.VLookup
withRange("A7:D9")
代替"A7:D9"
:
Dim x
With ThisWorkbook.Worksheets("Sheet1")
x = Application.VLookup("Justin", .Range("A7:D9"), 3, False)
Range("A1").Value = x
End With
Run Code Online (Sandbox Code Playgroud)
注意,x
应该是Variant
,因为如果没有找到,Application.VLookup
则返回Error 2042
( #N/A
)
归档时间: |
|
查看次数: |
27301 次 |
最近记录: |