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!
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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?
 

quej2003

New Member
Joined
Oct 5, 2010
Messages
49
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
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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.
 

quej2003

New Member
Joined
Oct 5, 2010
Messages
49

ADVERTISEMENT

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?
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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.
 

winneker

New Member
Joined
Jan 10, 2013
Messages
10
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:
 

Watch MrExcel Video

Forum statistics

Threads
1,114,002
Messages
5,545,439
Members
410,684
Latest member
LakTik
Top