View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Function to return formula

You can''t do it with a formula. You need to use a VBA function. E.g,

Public Function GetFormula(Rng As Range, _
Optional GetValueIfNoFormula As Boolean = True) As Variant

If Rng.Cells.Count 1 Then
GetFormula = CVErr(xlErrRef)
Exit Function
End If
If Rng.HasFormula = True Then
GetFormula = Rng.Formula
Else
If GetValueIfNoFormula = True Then
GetFormula = Rng.Value
Else
GetFormula = vbNullString
End If
End If

End Function

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email on the web site)


"Edward" wrote in message
ups.com...
What is the best way to return a cell's formula (using a function)?

I'm thinking along the lines of this (fictional) function:

=CELL("formula",A1)

TIA,

Ed