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.
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

excelnovicehouston

New Member
Joined
Feb 5, 2009
Messages
44
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?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,910
Messages
5,598,803
Members
414,260
Latest member
joishe

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
Top