Retrieve Formula from cell not value

Copper Contributor

I need to retrieve the existing formula from a cell not the value of the formula. 

what function(s) do I use to do that?

4 Replies
=FORMULATEXT(cellreference)

@Don_Raflik 

 

You can try FORMULATEXT

 

Cheers

@mathetes 

 

thank you for your reply. 

I am working in VBA. I did find an answer that worked. 

= .cells(cellrefernce).formula 

@Don_Raflik 

That would do it.  If your version of Excel does not feature FORMULATEXT() you could emulate it with a UDF

 

Function showFormula(target As Range) As String
    showFormula = target.Formula
End Function

 

called with

= showFormula(cellRef)

 

The Formula property and its variants can also be set from VBA, allowing the worksheet to be built from code.