Multiple WorksheetFunctions.Index/Match

KDS14589

Board Regular
Joined
Jan 10, 2019
Messages
182
Office Version
  1. 2016
Platform
  1. Windows
I have the following formula (which works fine) on a spreadsheet that I’m changing into VBA.

VBA Code:
="RGB("&INDEX(ColorList!$C$5:$C$1000,MATCH(Office!$A$2,ColorList!$F$5:$F$1000))&","&INDEX(ColorList!$D$5:$D$1000,MATCH(Office!$A$2,ColorList!$F$5:$F$1000))&","&INDEX(ColorList!$E$5:$E$1000,MATCH(Office!$A2,ColorList!$F$5:$F$1000))&")"

the formula gives me RGB(204,255,145)
But when I add beginning text or separating commas or a ending ) i get nothing.

This is a sample of my last failure.

VBA Code:
"RGB(" & WorksheetFunction.Index(ShGE04.Range("C5:C1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & "," &

WorksheetFunction.Index(ShGE04.Range("D5:D1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & "," &

WorksheetFunction.Index(ShGE04.Range("E5:E1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & ")"

ShGE04 is the CodeName for worksheet ColorList.
ShGE02 is the CodeName for worksheet Office.

If I ‘test’ one of those WorksheetFunction.Index/Match it will give me the correct number, it’s when I try to combine them that will not work.
Other worksheet code locations I have no problem adding text or special characters. But those are single Index/Match formulas where this problem has 3.


Can someone help?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Did you by any chance have it just the way you are showing it.
ie on separate lines which don't have a continuation mark "_" on the end
and a blank line in between.
This works fine and I tried yours adding the " _" to the end of each line and eliminating the spare blank rows and it worked fine for me too.

VBA Code:
Dim strOut As String
strOut = "RGB(" & _
                WorksheetFunction.Index(ShGE04.Range("C5:C1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & _
                "," & _
                WorksheetFunction.Index(ShGE04.Range("D5:D1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & _
                "," & _
                WorksheetFunction.Index(ShGE04.Range("D5:D1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & _
                ")"
 
Upvote 0
Solution
Did you by any chance have it just the way you are showing it.
ie on separate lines which don't have a continuation mark "_" on the end
and a blank line in between.
This works fine and I tried yours adding the " _" to the end of each line and eliminating the spare blank rows and it worked fine for me too.

VBA Code:
Dim strOut As String
strOut = "RGB(" & _
                WorksheetFunction.Index(ShGE04.Range("C5:C1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & _
                "," & _
                WorksheetFunction.Index(ShGE04.Range("D5:D1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & _
                "," & _
                WorksheetFunction.Index(ShGE04.Range("D5:D1000"), WorksheetFunction.Match(ShGE02.Range("A2"), ShGE04.Range("F5:F1000"), 0)) & _
                ")"
Yes, I had the (space)_ at the end of each formula, such as you do (in fact I had exactly like yours). I just removed them to show the formula better here. The one detail I didn’t have was the Dim as String. I had Dim as long. I made that correction and now it works.

THANKS
 
Upvote 0
Thanks for providing feedback on what you needed to do at your end. Glad we could help.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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