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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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