evaluate with strings and variables

excelnovicehouston

New Member
Joined
Feb 5, 2009
Messages
44
Hi,

I am try to do the following.

in excel I have a cell A1 = "IF(day>6, day+5, 6)"

i have a vba code

(ineq = the above IF equation)

function helpday(ineq)

day = sheet1.range("A5")
month = sheet1.range("A6")
helpday = evaluate(ineq)

End if


I want excel to evaluate this function, but it does not unless I do a replace(ineq, "day",day). however, I want the user to be able to change the equation from IF(day,x,y) to something like IF(month,x,y) and not have the code break without me adding a replace(month).... can excel do this?

many thanks for the help.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
can you elaborate?

i will likely be doing this routine in a for loop and so month and day would be passed into the function helpday as

helpday(month, day, ineq)

don't think it would be possible to construct it this way?
 
Upvote 0
Yes, if you must use a custom function you should pass it all the necessary arguments. But that won't help you with your Evaluate problem.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,390
Members
448,957
Latest member
Hat4Life

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