Set variable to value returned by complex array formula

jimrood

New Member
Joined
Dec 10, 2012
Messages
14
I'm attempting to set a variable in VBA to the value returned when executing this array formula during a loop:
{=INDEX(Tbl_Findings[RvwrLen],MATCH(1,(Tbl_Findings[Intake Number]=TEXT($B$2,"0"))*(Tbl_Findings[Question#]=A6),0))+2}

I've attempted to use the Evaluate method but can't seem to get the syntax correct. Cell reference $B$2 is fixed in my worksheet, whereas A6 can be replaced by my variable Q.

Dim Q as Integer

For Q = 1 to 25

Any help would be greatly appreciated.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
First see if you can print the formula text to a cell without the equal sign and curly braces, then add those on the worksheet. If ok, then try again with = and .formulaarray in the code. Finally, add =evaluate("formula here"). The formulaarray property is not needed for the last step.
 
Last edited:
Upvote 0
The formula works fine on the worksheet when contained in a cell. When I attempted to paste into the code it immediately flagged a problem with the quotes around the 0 in the Text function. I corrected it as follows: RebutStart = Evaluate("INDEX(Tbl_Findings[RvwrLen],MATCH(1,(Tbl_Findings[Intake Number]=TEXT($B$2,""0""))*(Tbl_Findings[Question'#]=Q),0))+2"). When I ran the macro it triggered a debug on this line.
 
Upvote 0
Did you enter the formula to the cell on the worksheet manually or via the code?

The extra quotes should be enough, but I would enter the formula from vba without an equal sign just to see how the string looks.
 
Last edited:
Upvote 0
The formula is entered into the cell manually. I'm trying to avoid having it on the worksheet. I think I discovered the source of the debug issue though. It doesn't like the variable Q in the evaluate method. Cell A6 contains the question number but since I'm using this array in a loop to cycle through questions 1-25 I'm not sure how to specify the required criteria.
 
Upvote 0
I got it to work! I assigned my variable Q to a static cell on the worksheet as it went through the loop and used that cell in my evaluate method formula. Thanks for you help with this.
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

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