Index Match multiple criteria

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Can someone tell me if this works in VBA?

Code:
https://trumpexcel.com/index-match/#Example-4-Lookup-Value-From-Multiple-ColumnCriteria

specifically:

Code:
=INDEX($C$2:$C$11,MATCH($E$3&"|"&$F$3,$A$2:A11&"|"&$B$2:$B$11,0))

I've tried it like this:

Code:
Dim Output

For Cols = 1 To 10

For Rows = 1 To 20

Output = Application.WorksheetFunction.Index(OutputRng, _
                    Application.WorksheetFunction.Match(Sheet1.Cells(Rows, 1).Value & "|" & _
                                                        Sheet1.Cells(Rows, 2).Value & "|" & _
                                                        Sheet1.Cells(Rows, Cols).Value & "|" & _
                                                        Sheet1.Cells(2, Cols).Value, _
                                                        Crit1Rng & "|" & _
                                                        Crit2Rng & "|" & _
                                                        Crit3Rng & "|" & _
                                                        Crit4Rng, _
                                                        0))

Next Rows

Next Cols

but I get an error:

Code:
Run-time '13':

Type mismatch

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Show your definitions of OutputRng and all the criteria ranges.
 
Upvote 0
Show your definitions of OutputRng and all the criteria ranges.
Code:
    Dim Crit1Rng As Range
    Set Crit1Rng = Sheet2.Range("A2:A10")
    
    
    Dim Crit2Rng As Range
    Set Crit2Rng = Sheet2.Range("B2:B10")

    Dim Crit3Rng As Range
    Set Crit3Rng = Sheet2.Range("C2:C10")

    Dim Crit4Rng As Range
    Set Crit4Rng = Sheet2.Range("D2:D10")


    Dim OutputRng As Range
    Set OutputRng = Sheet2.Range("E2:E10")
 
Upvote 0
I'm realising that you are doing an array concatenate on ranges - and I don't think you can do that in VBA the way you want. Sorry. Time for a redesign, I'd say. Like maybe doing something like this:
VBA Code:
    Dim Output
    Dim search_crit
    
    Dim Crit1Rng As Range
    Set Crit1Rng = Sheet2.Range("A2:A10")
    
    search_crit = Crit1Rng.Value
    
    Dim Crit2Rng As Range
    Set Crit2Rng = Sheet2.Range("B2:B10")
    
    Dim Crit3Rng As Range
    Set Crit3Rng = Sheet2.Range("C2:C10")
    
    Dim Crit4Rng As Range
    Set Crit4Rng = Sheet2.Range("D2:D10")

    For irow = 1 To 9
        search_crit(irow, 1) = search_crit(irow, 1) & "|" & Crit2Rng(irow) & "|" & Crit3Rng(irow) & "|" & Crit4Rng(irow)
    Next

to set up your criteria, and then use search_crit in the Match function, if you see what I mean?
 
Upvote 0
By the way, I used
VBA Code:
Option Base 1
on that code.
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,590
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top