简体   繁体   中英

How to write array formula in VBA syntax (not Excel-Formula)

To do lookup with two criteria, in Excel-Formula, it would be written as:

{MATCH(1, 1*(A1:A5=100)*(B1:B5=150), 0)}

How do i write the above formula in VBA syntax for the WorksheetFunction.Match function?

Consider:

Sub dural()
    Dim m As Long

    With Application.WorksheetFunction
        m = .Match(1, [1*(A1:A5=100)*(B1:B5=150)], 0)
    End With

    MsgBox m
End Sub

在此处输入图片说明

This shows both the array formula in the worksheet and the VBA equivalent.

I don't have enough rep to post a comment.. This is to aid anyone searching for how to use the answer from "Gary's Student" with variables. I wrestled with this for over an hour. The brackets [] used are a shortcut for evaluate(string) You have to replace those and wrap them in the evaluate method. Since the parameter is a string, you can construct the string yourself with the variables you need.

Sub dural()
Dim m As Long

With Application.WorksheetFunction
    m = .Match(1, evaluate("1*(A1:A5=100)*(B1:B5=150)"), 0)
End With

MsgBox m

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM