公式数组不返回任何内容或只返回#VALUE!使用评估时

时间:2018-02-27 05:45:03

标签: vba excel-vba excel

我正在尝试评估公式数组,以便从具有多个条件的工作表中查找值。工作表名称为Holiday_master

所以在另一张表Temp_data中,我尝试使用公式数组

来区分以下代码以在该单元格中设置该值
Public Function getCostMultiplier(dt As Date, wt As String) As Double   'dt is the date of entry, wt working time name "India Full Time","Singapore f........


        Dim lRow As Integer
        Dim we As Boolean
        we = IsWeekend(dt)
        Dim nhRange As Range
        Dim d As Double
        d = CDbl(dt)
        Dim location As String


        Select Case LCase(Trim(wt))
            Case "india full time 45"
                location = "INDIA"
            Case "singapore full time 40"
                location = "SINGAPORE"
            Case "uk full time 40"
                location = "UK"
        End Select

      Dim n As Integer
      'n = Application.Evaluate()
    lRow = Sheets("Holiday_master").Range("A1000").End(xlUp).Row + 1
    Dim formula As String
    Dim s As String
    s = Application.Evaluate("RC11")


    formula = printf("{=INDEX( Holiday_master!R2C3:R{0}C3,MATCH(1,(""{1}""=Holiday_master!R2C2:R{0}C2)*({2}=Holiday_master!R2C1:R{0}C1),0),1)}", lRow, location, d)
    ''''INDEX( Holiday_master!R2C3:R11C3,MATCH(1,("INDIA"=Holiday_master!R2C2:R11C2)*(43126=Holiday_master!R2C1:R11C1),0),1)
    n = Application.Evaluate(formula)

    getCostMultiplier = n

End Function


Public Function printf(mask As String, ParamArray tokens()) As String
Dim i As Long
For i = 0 To UBound(tokens)
    mask = Replace$(mask, "{" & i & "}", tokens(i))
Next
printf = mask
End Function

因此,在单元格的Temp_data表格中,我将公式设置为getCostMultiplier(RC11,RC4)', so obviously it reaches my function with parameters 26-01-2018 and INDIA`

所以在代码中我们有一个最终公式,我在那里注释INDEX( Holiday_master!R2C3:R11C3,MATCH(1,("INDIA"=Holiday_master!R2C2:R11C2)*(43101=Holiday_master!R2C1:R11C1),0),1) 但它没有像我预期的那样进行评估,或者这不能成为评估公式数组的方法。

如果我手动执行该单元格中的公式并在提交(ctrl+shift+enter)时,它会正确执行并返回值。

所以我不明白如何从VBA做到这一点或如何进行评估。

之前从未使用过评价

0 个答案:

没有答案