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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,955
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,955
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,955
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,109,411
Messages
5,528,617
Members
409,828
Latest member
99DodgeRam

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top