Embedding strings within strings within the Evaluate function...

Randall00

Board Regular
Joined
Jan 31, 2008
Messages
54
Like any good topic on MrExcel, this one begins with me pulling my hair out in frustration!

I've constructed a fairly straightforward Index/Match formula that involves a couple of columns within Tables in Excel's main interface that looks something like this:

Code:
=INDEX(A_OpenClose[Total Open Hours], MATCH("Central ArenaMonday", A_OpenClose[CONC],0))

The Evaluate function of VBA can take a text string and calculate the result, but because my formula contains a text string, I was advised that it I would be better off using the shorthand form of the Evaluate function...that is, to encase the formula in square brackets like this:

Code:
[INDEX(A_OpenClose[Total Open Hours], MATCH("Central ArenaMonday", A_OpenClose[CONC],0))]

This works pretty well, but there's a catch: the reason I brought the formula into VBA in the first place is because the text string within the formula needs to be a string variable that concatenates the (in this case) name of an arena with the day of the week.

In trying to get this to work, I created a variable called strConc that combines the two desire text strings into one and tried to incorporate it into the function. Lo and behold, I've managed to confuse both Excel and myself in trying to communicate exactly which part is a string to be evaluated and which part isn't.

All of the following attempts result in errors:

Code:
strConc = strArenaName & strWeekday

[INDEX(A_OpenClose[Total Open Hours], MATCH(strConc, A_OpenClose[CONC],0))]

[INDEX(A_OpenClose[Total Open Hours], MATCH("strConc", A_OpenClose[CONC],0))]

Evaluate("INDEX(A_OpenClose[Total Open Hours], MATCH(strConc, A_OpenClose[CONC],0))")

Evaluate("INDEX(A_OpenClose[Total Open Hours], MATCH(" & strConc & ", A_OpenClose[CONC],0))")

I've tried a few other things as well, but I've now buried myself in a deep misunderstanding of what these functions are doing.

There's a lot of information out there on how to incorporate quotation marks within text strings, but none seem to be related to the Evaluate function and since it's evaluating a text string right from the beginning, I can't exactly just stick a bunch of Chr(34)'s in there and fix it. Nor does it work if I try and declare the entire formula text as a single string variable and Evaluate that.

Incidentally, the only thing that seems to work is to put the the value of the strConc variable into a cell and then reference the cell address within the square brackets of the VBA function (which stands to reason because it's evaluating a worksheet function). However, I fear this little misadventure is already getting to dangerous levels of scope creep and I thought I'd ask if anyone knew anything about the way strings are handled in these two different Evaluate functions before investing too much time into a workaround for a workaround for a workaround, if you know what I mean. I would think there must be some way to do this.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi

Try:

Code:
Evaluate("INDEX(A_OpenClose[Total Open Hours], MATCH(""" & strConc & """, A_OpenClose[CONC],0))")
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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