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?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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)"
 
Upvote 0

Forum statistics

Threads
1,214,881
Messages
6,122,074
Members
449,064
Latest member
MattDRT

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