Build a formula from a string

NickAtNight

New Member
Joined
Sep 16, 2017
Messages
16
How do I build a formula from a string?

Lets say I have 10 user defined functions... (sam, fred, mary,...)

and I want to build the formula in the spreadsheet.

I can use a data validated cell to limit the function to the list of UDF's.

Then I want to create the formula as a string.
'=sam(v1,v2,v3)' or '=fred(v1,v2,v3)'


Then apply the string as a function.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
{it would be easier to do this in VBA or from a Userform. For this variant, I am trying to do this from the spreadsheet without extra code)
 
Upvote 0
I'm thinking that you have a validation drop down in B1 with the list of UDF's.
And you have your three variables in A1,A2,A3.

You want a cell to return the value of the function selected in B1, with the variables in A1,A2,A3.

First off, you cannot use worksheet formulas to change other formulas. Excel worksheet functions can't change the evironment of the worksheet (like change cell colors or change cell values). Worksheet formulas return values. So what you could do is have your UDF's

Sam, Fred, Mary, ...

Then have a dropdown with the strings "Sam", "Fred", "Mary", ...

Then create a name
Name: myResult
RefersTo: If(B1="Sam", Sam(A1,A2,A3), If(B1="Fred", Fred(A1,A2,A3), If(B1="Mary", Mary(A1,A2,A3), ... )))

Then put =myResult in a cell.
 
Upvote 0
Drat. 'you cannot use worksheet formulas to change other formulas'. I guess that answers this question.

Your proposed solution would work.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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