"Evalute" function with VBA Statement

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,621
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I guess this is not possible in vba :

Code:
MsgBox Evaluate("IIF(1=1,True,False)")

Am I correct ?

Thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
In VBA and Excel you use "If". "IIF" is an Access thing.
 
Upvote 0
IIf() is a VBA function. The Evaluate string must be an Excel formula, with or without a leading "=". In fact, it is executed in the Excel thread.

So you would write MsgBox Evaluate("IF(1=1,true,false)"). Capitalization does not matter.

PS.... And like an Excel formula, cells are referenced by Excel name, not by the VBA Range and Cells objects.

For example, MsgBox Evaluate("IF(A1=B1,C1,D1)"). That references those cells in the active worksheet.
 
Last edited:
Upvote 0
Huh... I'll be ****ed. 10+ years on this forum, I've never seen it used. Interesting.
 
Upvote 0
@joeu2004

Thanks for the confirmation ... Evaluate works only on excel formulaes and values and names not on vba statements such as IIF... that's what I thought.

Thanks Irobbo314 as well.
 
Upvote 0
@joeu2004

Thanks for the confirmation ... Evaluate works only on excel formulaes and values and names not on vba statements such as IIF... that's what I thought.
It is my understanding that VBA function are compiled (I guess at run time). The argument to the Evaluate function is a text string, so the VBA compiler would not be able to see VBA functions within it. My guess is that Evaluate passes its argument off to Excel for handling just like the formula in a cell would be. So, my conclusion is that the Evaluate function cannot evaluate VBA functions.
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,655
Members
449,113
Latest member
Hochanz

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