Execute a function stored in text format

Athena_4537

New Member
Joined
Mar 16, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

In an Excel sheet, I would like to introduce a function (in text format) which will then be retrieved to be applied to various cells, but with the contents of a cell (which will vary dynamically) via the LET function.

For example: Function: x+x^(1/2) or sin(x+1) or 2x^3-3x^2+5*x-3 LET formula obtained by concatenation: LET(x, B40, x+x^(1/2)) or LET(x, B40, sin(x+1)) And then, to execute this function in different places, with B40 which will vary depending on the cell where LET is created: LET(x, C40, x+x^(1/2)) then LET(x, D40, x+x^(1/2))

But how to execute and calculate this function stored in text format?

The function =LET(x, B40, x+x^(1/2)) used directly in a cell gives a result, but if the function (here x+x^(1/2)) changes, all the LETs need to be rewritten...
While a dynamic composition allows you to have the right LET everywhere, but... how to execute it afterwards.

The VBA function gives me errors 2015.

I am open to any solution, even in VBA.

Thank you in advance for your help.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If there are just a few functions that you need to select between, why not just build them into the LET statement?

Excel Formula:
=LET(condition,A1,x,B1,IF(condition=1,x+x^(1/2),IF(condition=2,SIN(x+1),IF(condition=3,2*x^3-3*x^2+5*x-3))))
 
Upvote 0
Another option, using a UDF:
Assuming that you calculate a well formed string:
1) insert in a standard module of your vba project the following code
VBA Code:
Function EvalString(ByVal myStr As String) As Variant
EvalString = Evaluate(myStr)
End Function
2) as last entry in your LET formula insert EvalString(TheString)
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Execute a function stored in text format
and Execute a function stored in text format
and Execute a function stored in text format
and Executer une fonction stockée au format texte
and Executer une fonction stockée au format texte - Macros et VBA Excel

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top