Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
If ... < or ... < then statement
I think I must not understand the "or" (and <) qualities of code, in an
If-Then statement. Here's my code: If MyType < "DIV" Or MyType < "UNM" Or MyType < "MOD" Then blah, blah, blah End If When MyType = "DIV", the code progresses to the [blah, blah, blah]. My little brain is trying to think that if MyType = "DIV", the code should bypass the [blah, blah, blah]. Please enlighten me. TIA |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
If ... < or ... < then statement
Hi,
With "or" at least one of them must be true to get an over all result to be true. So if MyType ="DIV" then the first condition is false but the other two are true then the true is executed. -- JP http://www.solutionsvba.com "zsplash" wrote in message ... I think I must not understand the "or" (and <) qualities of code, in an If-Then statement. Here's my code: If MyType < "DIV" Or MyType < "UNM" Or MyType < "MOD" Then blah, blah, blah End If When MyType = "DIV", the code progresses to the [blah, blah, blah]. My little brain is trying to think that if MyType = "DIV", the code should bypass the [blah, blah, blah]. Please enlighten me. TIA |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
If ... < or ... < then statement
When MyType equals "DIV", MyType does not equal "UNM" and it does not equal
"MOD", so the entire statement becomes If FALSE Or TRUE Or TRUE Then blah blah End If or If TRUE Then blah blah End If In fact, your code will always go in to the Then statement, regardless of the contents of MyType. In spoken English, we tend to use Or in this sort of statement when we really mean And. You don't want Or's here, you want And's. If MyType < "DIV" And MyType < "UNM" And MyType < "MOD" Then -- Cordially, Chip Pearson Microsoft MVP - Excel www.cpearson.com "zsplash" wrote in message ... I think I must not understand the "or" (and <) qualities of code, in an If-Then statement. Here's my code: If MyType < "DIV" Or MyType < "UNM" Or MyType < "MOD" Then blah, blah, blah End If When MyType = "DIV", the code progresses to the [blah, blah, blah]. My little brain is trying to think that if MyType = "DIV", the code should bypass the [blah, blah, blah]. Please enlighten me. TIA |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
If ... < or ... < then statement
If you want it to bypass the blah in each of the three cases, you need to
change the ORs to ANDs: If MyType < "DIV" And MyType < "UNM" And MyType < "MOD" Then blah, blah, blah End If In your code, when MyType is equal to DIV it's not equal to the other two, and so the overall statement evaluates to True and blah is executed. Sometimes I find a Select Case statement to be clearer: Select Case MyType Case "DIV", "UNM", "MOD" 'do nothing Case Else blah End Select hth, Doug "zsplash" wrote in message ... I think I must not understand the "or" (and <) qualities of code, in an If-Then statement. Here's my code: If MyType < "DIV" Or MyType < "UNM" Or MyType < "MOD" Then blah, blah, blah End If When MyType = "DIV", the code progresses to the [blah, blah, blah]. My little brain is trying to think that if MyType = "DIV", the code should bypass the [blah, blah, blah]. Please enlighten me. TIA |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
If ... < or ... < then statement
You guys are too wonderful. When explained so well (as you each did), it
all sounds so reasonable/logical. Thanks so much (and for the quick response). st. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
If ... < or ... < then statement
Yes, this group is amazing! I've learned so much in the last year, it's
great to be able to return the favor. Doug "zsplash" wrote in message ... You guys are too wonderful. When explained so well (as you each did), it all sounds so reasonable/logical. Thanks so much (and for the quick response). st. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF statement inside a SUMIF statement.... or alternative method | Excel Worksheet Functions | |||
Reconcile Bank statement & Credit card statement & accounting data | Excel Worksheet Functions | |||
Embedding an OR statement in an IF statement efficiently | Excel Discussion (Misc queries) | |||
SUMIF statement with AND statement | Excel Discussion (Misc queries) | |||
appending and IF statement to an existing IF statement | Excel Worksheet Functions |