Using If...

Bnygren

Board Regular
Joined
Feb 11, 2004
Messages
94
I have some code that I'd like to execute if the variable "Period" equals certain values - 1, 4, 7, or 10. If it doesn't = those values I want to skip the code and continue on to the next step. Currently, my code reads as such:

If period = 1 Or 4 Or 7 Or 10 Then
Workbooks.Open Filename:= _
"J:\Finance\Databases\fy" & sht_yr & "\Flash\PH" & Wk5 & ".DLV.xls"
End If

Am I missing something? When I run the macro it executes this code even if the variable does not = 1, 4, 7, or 10.

Thanks,

Bob
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

Try

Code:
Select Case period
case 1,4,7,10
Workbooks.Open Filename:= _ 
"J:\Finance\Databases\fy" & sht_yr & "\Flash\PH" & Wk5 & ".DLV.xls" 
end select

or

Code:
If period = 1 Or period= 4 Or period=7 Or period=10 Then 
Workbooks.Open Filename:= _ 
"J:\Finance\Databases\fy" & sht_yr & "\Flash\PH" & Wk5 & ".DLV.xls" 
end if
 

Forum statistics

Threads
1,144,676
Messages
5,725,710
Members
422,636
Latest member
GatorsBucs

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
Top