【问题标题】:Worksheet Function with Index/Match具有索引/匹配的工作表函数
【发布时间】:2016-02-14 17:45:31
【问题描述】:

我认为我的语法有误,有人介意指出问题吗?

提前致谢

 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)), "")

【问题讨论】:

标签: excel indexing match worksheet-function


【解决方案1】:

IFERROR function 不能用作WorksheetFunction object。只要没有错误,该公式就可以工作,但是当WorksheetFunction.IfError 发挥作用以返回默认值(例如零长度字符串)时会阻塞。

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(...

当使用字符串引用静态单元格地址时,通常不需要 $ 绝对值,因为字符串不会改变。一个可能的例外是当您使用字符串用公式填充大量单元格时;没有从评估单个公式中得到结果。

【讨论】:

  • 宾果游戏。我最终稍微改变了它以使其工作(有一个工作表错误验证并且只有 vba 代码返回单元格的内容)但我确实尝试了这个并且它有效。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-06
  • 2017-10-22
  • 1970-01-01
  • 1970-01-01
  • 2015-05-10
  • 1970-01-01
相关资源
最近更新 更多