Return Cell formula, not result

  • Thread starter Thread starter Robert Randolph
  • Start date Start date
R

Robert Randolph

I want to return a cells formula string, not the result.
Example:

A B
1 =B1 20


If I reference cell A1, I want the following result

"=B1"

NOT "20"

Thanks

PS. What is the search syntax to search ALL words, not
just any word. I tried searching the newsgroups but
could not narrow the search.
 
Well, I found a way to do what I want with macros, but if
anyone has an easier way without using macros, please
post it.

Here is the macro

Function CellFormula(ThisCell As String) As String
With Worksheets("Sheet1")
CellFormula = .Range(ThisCell).Formula
End With
End Function

So when I put this into a cell, "=CellFormula(A1)", it
correctly returns the string "=B1", NOT the numeric
result of the formula which would be "20".

Thanks
 
Hi Robert,
I expect you want the argument to apply to the sheet you are on ?

Function GetFormula(Cell)
GetFormula = Cell.Formula
End Function

A1: =3*4
B1: =GetFormula(A1)
or with the macro in another file
B1: =pesonal.xls!getformula(A1)
or to look at the formula on another sheet
B1: =GetFormula(sheet1!A1)
B1: =GetFormula('sheet one'!A1)

Show FORMULA of another cell in Excel
http://www.mvps.org/dmcritchie/excel/formula.htm--
 
Back
Top