VBA Index Match with multiple criteria question

Terranova1340

New Member
Joined
Apr 21, 2018
Messages
1
Hi all hoping someone on here can give me a slap to the head and tell me what I am doing wrong.

I am trying to write and Index Match formula and I am running into an issue where I cannot pass the formula variables IE Sheet names

Code:
Range("D20").FormulaArray = "=INDEX(" & month_Sht_Name & "!B23:B40,MATCH('Month by Individual Analyst'!D16&'Month by Individual Analyst'!D$17,Month!$A$23:$A$40&'Month by Individual Analyst'!D$17,0))"

The code above works IF I replace the following code with the actual sheet name
Code:
" & month_Sht_Name & "

So when written like this: It works fine
Code:
Range("D20").FormulaArray = "=INDEX(Month!B23:B40,MATCH('Month by Individual Analyst'!D16&'Month by Individual Analyst'!D$17,Month!$A$23:$A$40&'Month by Individual Analyst'!D$17,0))"


I have spent quite a few hours playing with it and for the life of me I cannot figure out what I am doing wrong. Though I am sure it is something silly.


Any help would be greatly appreciated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Interesting issue. I attempted to recreate your workbook, then tried this code - and it works fine:

Code:
Public Sub sV()
  Dim s As String
  Dim month_Sht_Name As String

  month_Sht_Name = "Month"
  
  s = "=INDEX(" & month_Sht_Name & "!B23:B40,MATCH('Month by Individual Analyst'!D16&'Month by Individual Analyst'!D$17,Month!$A$23:$A$40&'Month by Individual Analyst'!D$17,0))"
  
  ActiveCell.FormulaArray = s
  
  Debug.Print s
End Sub

So it is probably a broader issue with the way your workbook is set up. Can you give some more context? Most helpful would be the specific "issue" you're "running into", maybe a sample of what D20 is (or what sheet it is on), what is on month_Sht_Name (and data type, and what is its value), what are the values of 'Month by Individual Analyst'...... and so on.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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