View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default array formulas and getformula UDF

Bob Phillips wrote...
I don't think you can, the braces are internal to Excel, to tell it to array
process the formula. As you know, you don't type them, Excel adds them as a
visual cue. It must also store something at the same time to tell itself how
to process it on a recalc.

....

But the udf in question just returns text, and its Range arguments
would have a HasArray property.

"Dave F" wrote in message
I use the following code to create a UDF, getformula:

Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
End Function

....
Example: I have a formula, =SUM(A1:B5*D1:E5), which is entered as an array
formula. How come the UDF returns it without the brackets {}? Anyway to get
the UDF to properly recognize an array formula?

....

If you want array formulas treated specially, add code to the udf.

Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
If Cell.HasArray Then GetFormula = "{" & GetFormula & "}"
End Function