[VBA] Multi-criteria Index-Match in VBA with Variables oh my!

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
789
Office Version
  1. 2010
Platform
  1. Windows
VBA Code:
Cells(ActiveCell.Row, "I").FormulaArray = "=INDEX('[Advert Creation Master 2020.xlsm]Advert Rows'!C43,MATCH(1,(" & papnam & "='[Advert Creation Master 2020.xlsm]Advert Rows'!C1)*(" & tpl & "='[Advert Creation Master 2020.xlsm]Advert Rows'!C3),0))"

Have a gander at that. Multi Criteria Index Match follows this structure:

{=Index([Results],match(1,([Criteria1]=[Criteria1Range])*([Criteria2]=[Criteria2Range]),0))}

So the Criteria 1 and Criteria 2 I need to change. I have them loaded as "papnam" and "tpl" - these variables are loaded in as "Wolverhampton Chronicle" and "WOL_18x8_3UK"

This gives me this:

VBA Code:
=INDEX('[Advert Creation Master 2020.xlsm]Advert Rows'!C43,MATCH(1,(Wolverhampton Chronicle='[Advert Creation Master 2020.xlsm]Advert Rows'!C1)*(WOL_18x8_3UK='[Advert Creation Master 2020.xlsm]Advert Rows'!C3),0))

So nearly there, but I do need to get a "" surrounding the criteria. So I do this:

VBA Code:
    Cells(ActiveCell.Row, "I").FormulaArray = "=INDEX('[Advert Creation Master 2020.xlsm]Advert Rows'!C43,MATCH(1,(" & " & papnam & " & "='[Advert Creation Master 2020.xlsm]Advert Rows'!C1)*(" & "& tpl & " & "='[Advert Creation Master 2020.xlsm]Advert Rows'!C3),0))"

And I get "unable to set the FormulaArray property of the range class"


Any ideas? Thanks.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Any ideas? Thanks.

Eureka!

VBA Code:
Cells(ActiveCell.Row, "I").FormulaArray = "=INDEX('[Advert Creation Master 2020.xlsm]Advert Rows'!AQ:AQ,MATCH(1,(" & Chr(34) & papnam & Chr(34) & "='[Advert Creation Master 2020.xlsm]Advert Rows'!A:A)*(" & Chr(34) & tpl & Chr(34) & "='[Advert Creation Master 2020.xlsm]Advert Rows'!C:C),0))"

I can "trick" VBA by using chr(34) which is the code for a quote. Take that. Also I noticed that R1C1 style formulas don't work for Array, so I've changed this to the Excel-style formula expression.
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

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