Get Formula

  • Thread starter Thread starter willemeulen
  • Start date Start date
W

willemeulen

I use the following VBA

Function GetFormula(Cell as Range) as String
GetFormula = Cell.Formula
End Function

When inserting =Getformula(A5) it actually returns the formula in writing like
"=A3*B3"

I would like to incoorparate the following

Make the code working when using vlookup to select the cell
=Getformula(Vlookup,A20,.......))

Retrun the actual working formula not the text, as I will have formula's in
a lookup table using the ROW() refference the make thins working.


Thanks,

W:-)
 
I see a couple of issues here

You have defined GetFormula as a string, thus a text string is the result.
A text string will not be treated like a formula.

The Vlookup function will return the result contained in a given cell, it
will not return the cell address.

I am not sure that you really can get a User Defined Function to insert a
formula in a cell. A function returns a result, the result may look like a
formula, but I don't know if you can get Excel to treat it as a formula.

VBA can add a formula to a cell. Activecell.formula="=A3*B3" would add a
functioning formula to the cell.

I think you may need to change to a button called or Event called macro to
get want you want

Private Sub Worksheet_Change(ByVal Target As Range)
'Do Stuff
End Sub


Will run everytime the sheet is changed. You could likely structure some
code to find the correct formula and put in into the correct cell or cells.
 
Back
Top