Finding out the formula of cell.

D

Daniel Bonallack

Hi,

Cell A1 I sometimes contains the formula "=B56", and other
times contains the formula "=F56".

Is there a function that returns to another cell (say B1),
the actual formula in A1? So in B1 I would see "'=F56".

Thanks in advance
Daniel
 
J

Jerry W. Lewis

Put the following User Defiend Function on a Module shet (in the Visual
Basic Editor)

Function getFormula(ByVal Target As Range)
getFormula = Target.Formula
End Function

and =getFormula(A1) in your cell B1.

Jerry
 
P

Paul Corrado

Daniel,

If you don't need to always have the cell contents available for viewing you
can just press

Ctrl+~

when you need the cell information and that will display all of the
worksheet formulae.

Use Ctrl+~ to toggle back to the "normal" view.

PC
 
D

Daniel Bonallack

Hi, thanks Paul, but I actually need to be able to create
an If statement.

For example (if there were a function called "FORMULA") in
cell B1 I would want:

=If(Formula(A1)="=B56","Formula is =B56","Formula is =F56")

Thanks
Daniel
 
P

Paul Corrado

Daniel,

It looks like you want the formula in B1 to change the formula in A1 and
that cannot be done.

You need a VB script, and I'm not able to help you with that, but I'm sure
someone else can.

PC
 
A

Anon

What makes the formula change? Inserting/deleting columns? You need to write
your IF statement so that the same happens in it as happens to the formula
itself.
 
D

Daniel Bonallack

Hmm, it seems from all the answers that I did not describe
my problem well - however, this one is exactly the answer
I need - thanks!

regards
Daniel
 
H

Harlan Grove

...
...
Function getFormula(ByVal Target As Range)
getFormula = Target.Formula
End Function

and =getFormula(A1) in your cell B1.
...

Curiosity: why 'ByVal'? You're not modifying Target in the udf.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top