As an example:
sub test()
If Range("A1") = 1 Or Range("A1") = 2 Then MsgBox "A1 equals either 1 or 2"
end sub
This is a discussion on VBA and IF/OR statement within the Excel Questions forums, part of the Question Forums category; I know how to use an IF statement in VBA . Is there a way to include an OR in ...
I know how to use an IF statement in VBA. Is there a way to include an OR in the IF statement? Any help or suggestions would be much appreciated.
Thanks,
Steve
As an example:
sub test()
If Range("A1") = 1 Or Range("A1") = 2 Then MsgBox "A1 equals either 1 or 2"
end sub
"The greatest challenge to any thinker is stating the problem in a way that will allow a solution." Bertrand Russell
String full If Tests with:
And
Or
Like: If (myVal is > 5 And myVal <> 0) Then
JSW: Try and try again: "The way of the Coder!"
Also, search the VBE help file for Using Select Case Statements.
Thanks for all of the helpful answers. I will go and try them now.
Thanks again,
Steve
Thank you, Oaktree.
RIP, Nate.
~Anne Troy
Thanks Joe Was
Your suggested
If (myVal is > 5 And myVal <> 0) Then
led me to
If (myVal is > 5 And myVal <> 0) Or (myVal is > 15 And myVal <> 10) Then
which was a great help
I was looking for "If with Or" statements in VBA and came across this thread. Two questions rose in my mind: does "myVal is > 5" work with your Excel? I have to leave out the "is"... and the other question: what is the reason for this combination of arguments? I can get the same result with the statement
If myVal > 5 Then
Nonetheless it helped me for the syntax. Thanks!
Gordon
Last edited by grotten; Jun 15th, 2012 at 03:49 AM.
Bookmarks