I think you are suffering from some confusion about how to write logical evaluation in code. First I'll explain why the following code doesn't work:
An If statement determines the value of a Boolean expression, and if that expression evaluates to True then it does the Then part. You have defined Str as a String. A String is not a Boolean expression. So your code doesn't work. It doesn't matter that you have chosen to assign the string "True of False" which looks like a logical expression, but it's still a String. The example below shows the difference:
The first MsgBox will show the string
True Or False
The second MsgBox will show the Boolean value
True
because the logical expression True Or False evaluates to True.

Originally Posted by
VAer
First step: I write Str = "C.A2 > 5 Or P.A5 <> 7"
Second Step: I look at current year table and determine if C.A2 > 5 is True or False, if it is True, I will substitute it with True. Str = "True Or P.A5 <> 7"
Third Step: I look at previous year table and determine if P.A5 <> 7 is True or False, if it is False, I will substitute it with False. Str ="True Or False"
You cannot build a logical expression using strings. You are also making this more complicated that it needs to be. There is no reason to build up a single variable like that. You ask, "In other words, how to write If C.A2 > 5 Or P.A5 <> 7 Then ? " The answer is: You write it exactly like that!
It appears that C.A2 and P.A5 are just placeholders for some other variables, so this isn't real code. The example in your first post is also not real code. I can't give you a real code answer unless you provide real code to start with.
Bookmarks