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
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,113,812
Messages
5,544,458
Members
410,613
Latest member
Texman
Top