M
MJP
I'm trying to populate a number of cells with an array formula and can't
seem to get it to work. Every time I try to run the code I get the 'Unable
to set FormulaArray property of the range class' message.
A previous posting suggested this was due to there being a limit of 256
characters to a VBA formulaarray. The formula I am using includes a long
file path and name as it references another workbook. This made the formula
over 256 characters, so I have tried to replace the file path with a
variable that it populated with the file path stored in a specific cell
(e.g. fold = a1 with a1 containing the full file ref.)
Despite trying a number of combinations I can't get it to work. My latest
stab at the formula is as follows :
s_Address = Cells(r, c).AddressLocal(True, False, xlA1)
s_ColumnName = Left(s_Address, InStr(1, _
s_Address, "$") - 1)
wtype_ref = s_ColumnName & wtype_row & "="
date_ref = "A" & r & "="
fold = Cells(2, 10).Value
Range(Cells(r, c), Cells(r, c)).FormulaArray = "=SUM(IF($C$3=" & fold &
"B$3:$B$311, IF(" & wtype_ref & fold & "$F$3:$F$311, IF(" & date_ref & fold
& "$E$3:$E$311," & fold & "$D$3:$D$311))))"
the value in cell(2,10) is the file path & file name & sheet name -
'G:\Data\M\[SCL.xls]D'!
Can anyone see where I am going wrong? The reason I am using wtype_ref in
the formula is that my code has to populate this formula into several
consecutive cells in a row and so the reference changes for each cell.
If I use the full file path in the above formula and enter it directly into
a cell(rather than by VBA) it works fine, so I believe my array is OK, but
suspect it's something to do with the variable I'm using to represent the
file reference?
Please help as I've spent what should have been a productive day in the
office working on this damn formula!!!
Thanks in advance,
Mitch
seem to get it to work. Every time I try to run the code I get the 'Unable
to set FormulaArray property of the range class' message.
A previous posting suggested this was due to there being a limit of 256
characters to a VBA formulaarray. The formula I am using includes a long
file path and name as it references another workbook. This made the formula
over 256 characters, so I have tried to replace the file path with a
variable that it populated with the file path stored in a specific cell
(e.g. fold = a1 with a1 containing the full file ref.)
Despite trying a number of combinations I can't get it to work. My latest
stab at the formula is as follows :
s_Address = Cells(r, c).AddressLocal(True, False, xlA1)
s_ColumnName = Left(s_Address, InStr(1, _
s_Address, "$") - 1)
wtype_ref = s_ColumnName & wtype_row & "="
date_ref = "A" & r & "="
fold = Cells(2, 10).Value
Range(Cells(r, c), Cells(r, c)).FormulaArray = "=SUM(IF($C$3=" & fold &
"B$3:$B$311, IF(" & wtype_ref & fold & "$F$3:$F$311, IF(" & date_ref & fold
& "$E$3:$E$311," & fold & "$D$3:$D$311))))"
the value in cell(2,10) is the file path & file name & sheet name -
'G:\Data\M\[SCL.xls]D'!
Can anyone see where I am going wrong? The reason I am using wtype_ref in
the formula is that my code has to populate this formula into several
consecutive cells in a row and so the reference changes for each cell.
If I use the full file path in the above formula and enter it directly into
a cell(rather than by VBA) it works fine, so I believe my array is OK, but
suspect it's something to do with the variable I'm using to represent the
file reference?
Please help as I've spent what should have been a productive day in the
office working on this damn formula!!!
Thanks in advance,
Mitch