2

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?

2 Answers 2

3

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

enter image description here

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

Sign up to request clarification or add additional context in comments.

2 Comments

Amazing! Thanks so much!
@Gary'sStudent How to replace, 100 and 150 using variables? I am getting error when I fill those value with variables. Seems not doing concatenation with & right.
2

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

1 Comment

This is too informative to be a comment! (Not sure what the "evaluate method" means, though...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.