VBA and IF/OR statement

scrandal

Board Regular
Joined
Jul 15, 2004
Messages
160
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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
As an example:

sub test()
If Range("A1") = 1 Or Range("A1") = 2 Then MsgBox "A1 equals either 1 or 2"
end sub
 
Upvote 0
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
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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