View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default A function that returns the formula of a cell as a string

Atem,

Give this version a try - it will replace single name references in cases like

=myName

but not in cases like

=myName * 4


HTH,
Bernie
MS Excel MVP

Function MyForm(myC As Range) As String
Dim myAdd As String
MyForm = myC.Formula
On Error GoTo NotName
myAdd = Range(Mid(MyForm, 2, Len(MyForm))).Address(False, False)
MyForm = "=" & myAdd
NotName:
End Function




"Lacty" wrote in message
...
On Mar 6, 3:06 pm, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
Atem,

AFAIK, there is no way - possibly using some Excel 4 XLM code, but that is often a dicey
proposition.

HTH,
Bernie
MS Excel MVP

"Lacty" wrote in message

...

Bernie


Thanks for the response. But isn't it possible within Excel other than
using a user defined function?


Kind regards


Atem


On Mar 6, 2:12 pm, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
Lacty,


Function MyForm(myC As Range) As String
MyForm = myC.Formula
End Function


Copy that code into a regular codemodule, then use it like


=MyForm(A3)


HTH,
Bernie
MS Excel MVP


"Lacty" wrote in message


...


Hi


Does anyone know how to write a formula which will return the formula
in another cell as a string?


e.g if A3 contains the formula A1+ A2, I want to write a formula in B3
with will return the formula in A3 as string '= A1 + A2. Hence the
value in B3 will be string '= A1 + A2


Thanks in advance


Lacty




Bernie

I have gone with the UDF. It very simple and easy to use. If I take
this one step further, I have some cells with range names so using the
udf MyForm() returns = RangeName. Is it possible to write a code or
function that would return the actual cell address as oppose to the
range name?

Thanks very much