question on VBA syntax

bentley1

Board Regular
Joined
Aug 17, 2012
Messages
85
I have an array formula in VBA:

Code:
For x = 1 To MatChgNum + 1
 
    Cells(13 * x + 3, 2).Select

Selection.FormulaArray = _
        "=INDEX(DB!R6C1:R500C1,SMALL(IF(DB!R6C2:R500C2=""m"",ROW(DB!R6C2:R500C2),""""),[B]x[/B])-ROW(DB!R6C2:R500C2)+1)"

when this outputs in the corresponding cell instead of 1 it comes out as x in the formula which is resulting in a name error. I think this is because the x is in quotes but is there a way to work around this?
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
You have to take the x OUT of the formula string, and concatenate the value of x into the string..

Try

Selection.FormulaArray = _
"=INDEX(DB!R6C1:R500C1,SMALL(IF(DB!R6C2:R500C2=""m"",ROW(DB!R6C2:R500C2),"""")," & x & ")-ROW(DB!R6C2:R500C2)+1)"
 

bentley1

Board Regular
Joined
Aug 17, 2012
Messages
85
Hi Jonmo1,

thanks for the reply! sorry had to go for a bit but will try now
 

Watch MrExcel Video

Forum statistics

Threads
1,122,806
Messages
5,598,188
Members
414,218
Latest member
speedbit

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
Top