Index-match with multiple criteria in worksheetfunction

dionysus_83

New Member
Joined
Feb 24, 2016
Messages
30
Hi all,

Well, I`m stuck, I couldn`t find adequate answer in forums. Here is the code:

Code:
matchRECORD0 = Application.WorksheetFunction.Index(Sheets("TEMPDB").Range("D" & lrSJIMPORT2 + 1 & ":D" & lrCHIMPORT2), _
Application.WorksheetFunction.Match(Sheets("STATIONS").Cells(RARSTAT2, 2) & Sheets("STATIONS").Cells(1, cARTIST), _
Sheets("TEMPDB").Range("C" & lrSJIMPORT2 + 1 & ":C" & lrCHIMPORT2) & Sheets("TEMPDB").Range("A" & lrSJIMPORT2 + 1 & ":A" & lrCHIMPORT2)))

Entire code is quite large but I receive error on this part! I know it should be set in array but I don`t know how to do that, so question is:

How to make this worksheetfunction as array?

Thnx
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I would add helper columns on both sheets to concatenate the ranges.
Then do your matching on those columns.

And instead of doing
application.worksheetfunction.Index(application.worksheetfunction.match

First, drop the worksheet function, and just use application.match
And assign the result of the match to a variable.
Test the variable for error
Then use built in vba syntax to do the indexing..

Rich (BB code):
Dim MyVariable
MyVariable = Application.Match(Sheets("STATIONS").Cells(ConcatenatedColumn, 2),Sheets("TEMPDB").Range("E" & lrSJIMPORT2 + 1 & ":E" & lrCHIMPORT2),0)
'E is the concatenated column on TEMPDB Sheet.
If Not IsError(MyVariable) Then
    matchRECORD0 = Sheets("TEMPDB").Range("D" & MyVariable + lrSJIMPORT2)
End If
 
Upvote 0
I would add helper columns on both sheets to concatenate the ranges.
Then do your matching on those columns.

And instead of doing
application.worksheetfunction.Index(application.worksheetfunction.match

First, drop the worksheet function, and just use application.match
And assign the result of the match to a variable.
Test the variable for error
Then use built in vba syntax to do the indexing..

Rich (BB code):
Dim MyVariable
MyVariable = Application.Match(Sheets("STATIONS").Cells(ConcatenatedColumn, 2),Sheets("TEMPDB").Range("E" & lrSJIMPORT2 + 1 & ":E" & lrCHIMPORT2),0)
'E is the concatenated column on TEMPDB Sheet.
If Not IsError(MyVariable) Then
    matchRECORD0 = Sheets("TEMPDB").Range("D" & MyVariable + lrSJIMPORT2)
End If

Excellent suggestion, and I considered that as last chance solution because rest of code is quite large and interacts with different parts of that same table. I didnt think too much in advance so came to this problem. I would like to avoid if possible to use concatenated column solution as I will have ton of work to change rest of code too. But still, thnx a lot as this is a solution to my problem.
 
Upvote 0
You're welcome.

That's your choice of course. But I'd pose this question..
Which time is more valueable, Time spent designing/writing the code/project, or the Time spent Executing/Using the code/project ?
 
Last edited:
Upvote 0
You could try like this:

Code:
x = Sheets("TEMPDB").Range("A" & lrSJIMPORT2 + 1 & ":D" & lrCHIMPORT2)
For i = LBound(x, 1) To UBound(x, 1)
    If LCase(x(i, 3)) = LCase(Sheets("STATIONS").Cells(RARSTAT2, 2)) Then
        If LCase(x(i, 1)) = LCase(Sheets("STATIONS").Cells(1, cARTIST)) Then
            matchRECORD0 = x(i, 4)
            Exit For
        End If
    End If
Next
 
Upvote 0
Well said @Jonmo1. I will go trough rest of my code to change what is neccessary and use your suggestion.

Thnx a lot
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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