在Excel VBA中使用匹配和索引功能

时间:2014-10-15 18:01:40

标签: excel vba indexing match

我正在尝试使用VBA在照片度量报告中查找值(列和行标签的数值角度值以及数组中的数值)。我正在尝试使用匹配函数和索引函数。但是,在我的UDF中,在工作表中工作的代码会自动返回#VALUE错误。

    Dim H_10 As Double
    Dim V_5 As Double
    Dim hangle As Double
    Dim vangle As Double


    H_10 = WorksheetFunction.MRound(h, 10)
    V_5 = WorksheetFunction.MRound(v, 5)
            ' rounds off angle values to match row and collumn headers
    hangle = Application.WorksheetFunction.Match(H_10, "B42:T42", 0)
    vangle = Application.WorksheetFunction.Match(V_5, "A43:A79", 0)
            'looks up the row/column index
   cd = Application.Index("B43:T79", hangle, vangle, 0)
            ' uses row and column index to find value in array

我最初在索引函数中使用了匹配函数,但将它们拉出来进行故障排除。

我尝试过简单地将我知道的数字放在索引函数中,但是当它或匹配处于活动状态时,我会在整个主板上出现#VALUE错误。

1 个答案:

答案 0 :(得分:0)

WorksheetFunctions要求使用范围对象而不是范围字符串。将范围字符串更改为:Range("RangeString")

相关问题