带索引/匹配的工作表函数
我相信我的语法是错误的,有人会指出这个问题吗?
提前致谢
result = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Index_ (Range("Sheet10!$AC$40:$AC$118"), Application.WorksheetFunction.Match(Range("Sheet10!E3"),_ Range("Sheet10!$AD$40:$AD$118"), 0)), "")
IFERROR函数不能用作WorksheetFunction对象 。 只要没有错误,公式就会工作,但当WorksheetFunction.IfError
发挥作用以返回默认值(例如零长度string)时会窒息。
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方法 。
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(...
当提到一个带有string的静态单元地址时,通常不需要$绝对制造商,因为string不会改变。 一个可能的例外是当您使用string填充公式大量的单元格; 没有从评估一个单一的公式得出结果。