FormulaArray in VBA

quej2003

New Member
Joined
Oct 5, 2010
Messages
49
Hi I keep getting a "run time error 1004 unable to set the formulaarray property of the range class" at this point in my VBA...I can't seem to figure out why:

Code:
Set wsout = ActiveSheet

wsout.Range("BS59").FormulaArray = "=IFERROR((INDEX(EC$2:EC$9999,MATCH(1,(OFFSET(A$1,MATCH(BO59,AE$2:AE$199,0),0)=EA$2:EA$9999)*(BU$1=EB$2:EB$9999),0))/INDEX(EC$2:EC$9999,MATCH(1,(OFFSET(A$1,MATCH(BO59,AE$2:AE$199,0),0)=EA$2:EA$9999)*(EOMONTH(BU$1,-1)=EB$2:EB$9999),0)))-1,"""")"

I read about the character limit of 255, but from what I see this is only 241 so doesn't seem to be that, any help would be appreciated!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You can't enter that formula as an array formula manually in the spreadsheet. Does it give you the correct result if you change FormulaArray to Formula?
 
Upvote 0
You can't enter that formula as an array formula manually in the spreadsheet. Does it give you the correct result if you change FormulaArray to Formula?

changing ,"""") at the end of ,0) makes it work fine...even when I use this in VBA it doesnt work
 
Upvote 0
I don't think you're understanding. Using FormulaArray on a formula that can't be entered as an array formula will give an error.
 
Upvote 0
I don't think you're understanding. Using FormulaArray on a formula that can't be entered as an array formula will give an error.

I guess so because the formula I provided seems fine to be entered as an array formula in excel itself...bar what I noted above clearly, what am I missing here?
 
Upvote 0
I did find this information though, and it probably is the cause of your problem. FormulaArray can be used with A1-style notation, but is meant to be used with R1C1 notation.
The R1C1 equivalent formula must be less than 255 characters, and your A1 style formula is already at 240 characters.

Working With Range.FormulaArray In VBA | RAD Excel

If you can explain what you are trying to do with your formula exactly, perhaps someone can come up with a shorter formula.
 
Upvote 0
I too am trying to enter a FormulaArray in VBA. im getting the same error '1004' and I believe I have just over 220 characters. when I hover over each of the components in the formula everything seems to be working correctly except for the syntax of combining my 5 variable criteria. Essentially ive named five variables pc1 - pc5 and I want to do a sumif in the same criteria range (single column) for any/all of these 5 variables.

Code:
Select Case Left(wf.Trim(wf.Clean(LCase(cl))), 2)
Case "bp", "p1": pc1 = Left(wf.Trim(wf.Clean(LCase(cl))), 10)
pc2 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 12, 3)
pc3 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 16, 3)
pc4 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 20, 3)
pc5 = Left(wf.Trim(wf.Clean(LCase(cl))), 7) & Mid(cl, 24, 3)

For Each cl1 In ws_port.Range(Cells(cl.Row, Range("curr_zfin").Offset(, -5).Column), Cells(cl.Row, Range("curr_zfin").Column))
cl1.FormulaArray = "=Sum(SumIFs('[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$D$7:$D$2500,'[ZFIN.xlsx]" & Cells(Range("curr_zfin").Row, cl1.Column) & "'!$B$7:$B$2500,{" & pc1 & "," & pc2 & "," & pc3 & "," & pc4 & "," & pc5 & "}))"
cl1.Value = cl1.Value * -1
cl1.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* "" - ""??_);_(@_)"
Next cl1
Code:
 
Upvote 0

Forum statistics

Threads
1,213,483
Messages
6,113,919
Members
448,533
Latest member
thietbibeboiwasaco

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