ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Referencing a formula (as text) (https://www.excelbanter.com/excel-discussion-misc-queries/24261-referencing-formula-text.html)

Nelson

Referencing a formula (as text)
 
Hi, can anyone help with the following?

I want to pick up a formula (written as text) from one cell so it can be
used in another function? This will then be applied to a range of cells by
filling-down.

For example if I write a function as VLOOKUP(X,Table,3,false) without the =
sign and therefore store it in a cell as text, I want to be able to
reference that cell and apply the function.

Is this possible?

Nelson



Bob Umlas, Excel MVP

You'd need a macro to do that. If that formula were in D3, for example, this
line of VBA would do it:
Answer = evaluate("=" & [d3])

Bob Umlas

"Nelson" wrote:

Hi, can anyone help with the following?

I want to pick up a formula (written as text) from one cell so it can be
used in another function? This will then be applied to a range of cells by
filling-down.

For example if I write a function as VLOOKUP(X,Table,3,false) without the =
sign and therefore store it in a cell as text, I want to be able to
reference that cell and apply the function.

Is this possible?

Nelson




Dave Peterson

Just to add to Bob's response....

You'd need a User Defined Function.

This one worked ok for me:

Option Explicit
Function Eval(str As String) As Variant
With Application
.Volatile
Eval = .Evaluate(str)
End With
End Function

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=eval(a1)

Where A1 contains your formula/string.

Nelson wrote:

Hi, can anyone help with the following?

I want to pick up a formula (written as text) from one cell so it can be
used in another function? This will then be applied to a range of cells by
filling-down.

For example if I write a function as VLOOKUP(X,Table,3,false) without the =
sign and therefore store it in a cell as text, I want to be able to
reference that cell and apply the function.

Is this possible?

Nelson


--

Dave Peterson

Nelson

Thanks everyone,

Will look at David McRitches site.

Nelson



"Dave Peterson" wrote in message
...
Just to add to Bob's response....

You'd need a User Defined Function.

This one worked ok for me:

Option Explicit
Function Eval(str As String) As Variant
With Application
.Volatile
Eval = .Evaluate(str)
End With
End Function

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=eval(a1)

Where A1 contains your formula/string.

Nelson wrote:

Hi, can anyone help with the following?

I want to pick up a formula (written as text) from one cell so it can be
used in another function? This will then be applied to a range of cells
by
filling-down.

For example if I write a function as VLOOKUP(X,Table,3,false) without the
=
sign and therefore store it in a cell as text, I want to be able to
reference that cell and apply the function.

Is this possible?

Nelson


--

Dave Peterson





All times are GMT +1. The time now is 07:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com