Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
SUMIF statement with AND statement Eric D Excel Discussion (Misc queries) 2 July 14th 08 07:24 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM


All times are GMT +1. The time now is 03:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"