Index/Match 的工作表函数
Worksheet Function with Index/Match
我认为我的语法有误,有人介意指出这个问题吗?
提前致谢
result = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Index_
(Range("Sheet10!$AC:$AC8"), Application.WorksheetFunction.Match(Range("Sheet10!E3"),_
Range("Sheet10!$AD:$AD8"), 0)), "")
IFERROR function cannot be used as a WorksheetFunction object。只要没有错误,该公式就会起作用,但是当 WorksheetFunction.IfError
开始发挥作用时,该公式会阻塞 return 默认值(例如零长度字符串)。
Sub ject()
Dim result As Variant
'this works if a match is found
result = Application.WorksheetFunction.IfError( _
Application.WorksheetFunction.Index(Range("Sheet10!AC40:AC118"), _
Application.WorksheetFunction.Match(Range("Sheet10!E3"), Range("Sheet10!AD40:AD118"), 0)), "")
Debug.Print result
End Sub
您可以试试 Application.Evaluate method。
Sub jective()
Dim result As Variant
'this works on match or no match
result = Application.Evaluate("IFERROR(INDEX(Sheet10!AC40:AC118, " & _
"MATCH(Sheet10!E3, Sheet10!AD40:AD118, 0)), ""nothing"")")
Debug.Print result
End Sub
通常可以有Application.Index(...
或WorksheetFunction.Index(...
,但不需要Application.WorksheetFunction.Index(...
。
当使用字符串引用静态单元格地址时,通常不需要 $ 绝对标记,因为字符串不会更改。一个可能的例外是当您使用字符串用公式填充大量单元格时;无法通过评估单个公式获得结果。
我认为我的语法有误,有人介意指出这个问题吗?
提前致谢
result = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Index_
(Range("Sheet10!$AC:$AC8"), Application.WorksheetFunction.Match(Range("Sheet10!E3"),_
Range("Sheet10!$AD:$AD8"), 0)), "")
IFERROR function cannot be used as a WorksheetFunction object。只要没有错误,该公式就会起作用,但是当 WorksheetFunction.IfError
开始发挥作用时,该公式会阻塞 return 默认值(例如零长度字符串)。
Sub ject()
Dim result As Variant
'this works if a match is found
result = Application.WorksheetFunction.IfError( _
Application.WorksheetFunction.Index(Range("Sheet10!AC40:AC118"), _
Application.WorksheetFunction.Match(Range("Sheet10!E3"), Range("Sheet10!AD40:AD118"), 0)), "")
Debug.Print result
End Sub
您可以试试 Application.Evaluate method。
Sub jective()
Dim result As Variant
'this works on match or no match
result = Application.Evaluate("IFERROR(INDEX(Sheet10!AC40:AC118, " & _
"MATCH(Sheet10!E3, Sheet10!AD40:AD118, 0)), ""nothing"")")
Debug.Print result
End Sub
通常可以有Application.Index(...
或WorksheetFunction.Index(...
,但不需要Application.WorksheetFunction.Index(...
。
当使用字符串引用静态单元格地址时,通常不需要 $ 绝对标记,因为字符串不会更改。一个可能的例外是当您使用字符串用公式填充大量单元格时;无法通过评估单个公式获得结果。