VBA another way to write or statement

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I am pretty new to VBA. Just wondering is there a shorter way to write multiple or's in VBA. Thanks in advance

Code:
If (gradelevel = 1 Or gradelevel = 2 Or gradelevel = 3 Or gradelevel = 4 Or gradelevel = 5 Or gradelevel = 6) Then
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You could use a Select Case Statement, like
Code:
    Select Case gradelevel
        Case 1 To 6
            'do something
    End Select
 
Upvote 0
Another way...
Code:
If gradelevel Like "[1-6]" Then
And yet another way (although this would pass floating point values if your gradelevel is not guaranteed to be integer)...
Code:
If gradelevel > 0 and gradelevel < 7 Then
 
Last edited:
Upvote 0
Thank you both!! I appreciate any guidance that I can get!! Have a great evening!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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