Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Remove Holidays as DateSerial using Case

I've finally got some code put together that does exactly what I want.
However, I forgot that I need to remove holidays!! This code asks the user
which month to set up, and whether they want to include Saturdays and Sundays
before the worksheets for the month are set up. I'm using the CASE structure
to do this.

What I need is a CASE statement that will NOT include holidays. I can have
the serial numbers or dates for the holidays listed somewhere, but I can't
figure out the code to make it work.

Would someone mind taking a look? Thanks Much!!

Here's the full code:

Sub CreateMonth()

Dim SH As Worksheet
Dim wCtr As Long
Dim myDate As Variant
Dim D As Date, Y As Long
Dim N As String
Dim DDate As String
Dim CaseSat As String
Dim CaseSun As String

Worksheets("DMR Master").Activate
Set SH = ActiveSheet

myDate = InputBox(Prompt:="Enter the FIRST DAY of the Month you want to
Create", _
Default:=Format(Date, "mm/dd/yy"))

Msg = "Do You Want to Include Saturdays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSat = vbSaturday
Else
CaseSat = ""
End If

Msg = "Do You Want to Include Sundays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSun = vbSunday
Else
CaseSun = ""
End If

Application.ScreenUpdating = False
myDate = CDate(myDate)

For iCtr = DateSerial(Year(myDate), Month(myDate), 1) To
DateSerial(Year(myDate), _
Month(myDate) + 1, 0)
Select Case Weekday(iCtr)
Case Is = CaseSat '(Does all days, remove '& does only weekdays)
'do nothing
Case Is = CaseSun '(Does all days, remove ' & does only weekdays)
'do nothing
Case Else
Application.StatusBar = D
SH.Copy after:=Sheets(Sheets.Count)
N = Sheets.Count - 3
'ActiveSheet.Range("A1").Value = D
ActiveSheet.Name = Format(iCtr, "dddd mm-dd")
Range("H4") = Format(iCtr, "mm/dd/yy")
Range("H8") = N
End Select
Next

Sheets(4).Activate
Range("D8") = N

For wCtr = 4 To Worksheets.Count
'If Worksheets(wCtr).Name = Worksheets("Setup").Name Then
'skip it
'Else
Worksheets(wCtr).Activate
Range("D8") = N
'End If
Next wCtr

Worksheets("Setup").Activate
Application.StatusBar = False
Application.ScreenUpdating = True

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Remove Holidays as DateSerial using Case

Dim res as Variant


.. . .

For iCtr = DateSerial(Year(myDate), Month(myDate), 1) To
DateSerial(Year(myDate), _
Month(myDate) + 1, 0)

res = Application.Match(clng(ictr),Range("Holidays"),0)
if iserror(res) then
Select Case Weekday(iCtr)
Case Is = CaseSat '(Does all days, remove '& does only weekdays)
'do nothing
Case Is = CaseSun '(Does all days, remove ' & does only weekdays)
'do nothing
Case Else
Application.StatusBar = D
SH.Copy after:=Sheets(Sheets.Count)
N = Sheets.Count - 3
'ActiveSheet.Range("A1").Value = D
ActiveSheet.Name = Format(iCtr, "dddd mm-dd")
Range("H4") = Format(iCtr, "mm/dd/yy")
Range("H8") = N
End Select
end if
Next


--
Regards,
Tom Ogilvy

"David" wrote in message
...
I've finally got some code put together that does exactly what I want.
However, I forgot that I need to remove holidays!! This code asks the user
which month to set up, and whether they want to include Saturdays and
Sundays
before the worksheets for the month are set up. I'm using the CASE
structure
to do this.

What I need is a CASE statement that will NOT include holidays. I can have
the serial numbers or dates for the holidays listed somewhere, but I can't
figure out the code to make it work.

Would someone mind taking a look? Thanks Much!!

Here's the full code:

Sub CreateMonth()

Dim SH As Worksheet
Dim wCtr As Long
Dim myDate As Variant
Dim D As Date, Y As Long
Dim N As String
Dim DDate As String
Dim CaseSat As String
Dim CaseSun As String

Worksheets("DMR Master").Activate
Set SH = ActiveSheet

myDate = InputBox(Prompt:="Enter the FIRST DAY of the Month you want to
Create", _
Default:=Format(Date, "mm/dd/yy"))

Msg = "Do You Want to Include Saturdays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSat = vbSaturday
Else
CaseSat = ""
End If

Msg = "Do You Want to Include Sundays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSun = vbSunday
Else
CaseSun = ""
End If

Application.ScreenUpdating = False
myDate = CDate(myDate)

For iCtr = DateSerial(Year(myDate), Month(myDate), 1) To
DateSerial(Year(myDate), _
Month(myDate) + 1, 0)
Select Case Weekday(iCtr)
Case Is = CaseSat '(Does all days, remove '& does only weekdays)
'do nothing
Case Is = CaseSun '(Does all days, remove ' & does only weekdays)
'do nothing
Case Else
Application.StatusBar = D
SH.Copy after:=Sheets(Sheets.Count)
N = Sheets.Count - 3
'ActiveSheet.Range("A1").Value = D
ActiveSheet.Name = Format(iCtr, "dddd mm-dd")
Range("H4") = Format(iCtr, "mm/dd/yy")
Range("H8") = N
End Select
Next

Sheets(4).Activate
Range("D8") = N

For wCtr = 4 To Worksheets.Count
'If Worksheets(wCtr).Name = Worksheets("Setup").Name Then
'skip it
'Else
Worksheets(wCtr).Activate
Range("D8") = N
'End If
Next wCtr

Worksheets("Setup").Activate
Application.StatusBar = False
Application.ScreenUpdating = True

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Remove Holidays as DateSerial using Case

Bombed on the res = Application line.
Do I need to have the Range of Holidays defined somewhere?
Thanks for the help!

"Tom Ogilvy" wrote:

Dim res as Variant


.. . .

For iCtr = DateSerial(Year(myDate), Month(myDate), 1) To
DateSerial(Year(myDate), _
Month(myDate) + 1, 0)

res = Application.Match(clng(ictr),Range("Holidays"),0)
if iserror(res) then
Select Case Weekday(iCtr)
Case Is = CaseSat '(Does all days, remove '& does only weekdays)
'do nothing
Case Is = CaseSun '(Does all days, remove ' & does only weekdays)
'do nothing
Case Else
Application.StatusBar = D
SH.Copy after:=Sheets(Sheets.Count)
N = Sheets.Count - 3
'ActiveSheet.Range("A1").Value = D
ActiveSheet.Name = Format(iCtr, "dddd mm-dd")
Range("H4") = Format(iCtr, "mm/dd/yy")
Range("H8") = N
End Select
end if
Next


--
Regards,
Tom Ogilvy

"David" wrote in message
...
I've finally got some code put together that does exactly what I want.
However, I forgot that I need to remove holidays!! This code asks the user
which month to set up, and whether they want to include Saturdays and
Sundays
before the worksheets for the month are set up. I'm using the CASE
structure
to do this.

What I need is a CASE statement that will NOT include holidays. I can have
the serial numbers or dates for the holidays listed somewhere, but I can't
figure out the code to make it work.

Would someone mind taking a look? Thanks Much!!

Here's the full code:

Sub CreateMonth()

Dim SH As Worksheet
Dim wCtr As Long
Dim myDate As Variant
Dim D As Date, Y As Long
Dim N As String
Dim DDate As String
Dim CaseSat As String
Dim CaseSun As String

Worksheets("DMR Master").Activate
Set SH = ActiveSheet

myDate = InputBox(Prompt:="Enter the FIRST DAY of the Month you want to
Create", _
Default:=Format(Date, "mm/dd/yy"))

Msg = "Do You Want to Include Saturdays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSat = vbSaturday
Else
CaseSat = ""
End If

Msg = "Do You Want to Include Sundays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSun = vbSunday
Else
CaseSun = ""
End If

Application.ScreenUpdating = False
myDate = CDate(myDate)

For iCtr = DateSerial(Year(myDate), Month(myDate), 1) To
DateSerial(Year(myDate), _
Month(myDate) + 1, 0)
Select Case Weekday(iCtr)
Case Is = CaseSat '(Does all days, remove '& does only weekdays)
'do nothing
Case Is = CaseSun '(Does all days, remove ' & does only weekdays)
'do nothing
Case Else
Application.StatusBar = D
SH.Copy after:=Sheets(Sheets.Count)
N = Sheets.Count - 3
'ActiveSheet.Range("A1").Value = D
ActiveSheet.Name = Format(iCtr, "dddd mm-dd")
Range("H4") = Format(iCtr, "mm/dd/yy")
Range("H8") = N
End Select
Next

Sheets(4).Activate
Range("D8") = N

For wCtr = 4 To Worksheets.Count
'If Worksheets(wCtr).Name = Worksheets("Setup").Name Then
'skip it
'Else
Worksheets(wCtr).Activate
Range("D8") = N
'End If
Next wCtr

Worksheets("Setup").Activate
Application.StatusBar = False
Application.ScreenUpdating = True

End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Remove Holidays as DateSerial using Case

GOT IT!
I set up some dates and gave the range the name HOLIDAYS and it worked
perfect!
Thank you so much for your time!!

"Tom Ogilvy" wrote:

Dim res as Variant


.. . .

For iCtr = DateSerial(Year(myDate), Month(myDate), 1) To
DateSerial(Year(myDate), _
Month(myDate) + 1, 0)

res = Application.Match(clng(ictr),Range("Holidays"),0)
if iserror(res) then
Select Case Weekday(iCtr)
Case Is = CaseSat '(Does all days, remove '& does only weekdays)
'do nothing
Case Is = CaseSun '(Does all days, remove ' & does only weekdays)
'do nothing
Case Else
Application.StatusBar = D
SH.Copy after:=Sheets(Sheets.Count)
N = Sheets.Count - 3
'ActiveSheet.Range("A1").Value = D
ActiveSheet.Name = Format(iCtr, "dddd mm-dd")
Range("H4") = Format(iCtr, "mm/dd/yy")
Range("H8") = N
End Select
end if
Next


--
Regards,
Tom Ogilvy

"David" wrote in message
...
I've finally got some code put together that does exactly what I want.
However, I forgot that I need to remove holidays!! This code asks the user
which month to set up, and whether they want to include Saturdays and
Sundays
before the worksheets for the month are set up. I'm using the CASE
structure
to do this.

What I need is a CASE statement that will NOT include holidays. I can have
the serial numbers or dates for the holidays listed somewhere, but I can't
figure out the code to make it work.

Would someone mind taking a look? Thanks Much!!

Here's the full code:

Sub CreateMonth()

Dim SH As Worksheet
Dim wCtr As Long
Dim myDate As Variant
Dim D As Date, Y As Long
Dim N As String
Dim DDate As String
Dim CaseSat As String
Dim CaseSun As String

Worksheets("DMR Master").Activate
Set SH = ActiveSheet

myDate = InputBox(Prompt:="Enter the FIRST DAY of the Month you want to
Create", _
Default:=Format(Date, "mm/dd/yy"))

Msg = "Do You Want to Include Saturdays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSat = vbSaturday
Else
CaseSat = ""
End If

Msg = "Do You Want to Include Sundays as a Workday?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then
CaseSun = vbSunday
Else
CaseSun = ""
End If

Application.ScreenUpdating = False
myDate = CDate(myDate)

For iCtr = DateSerial(Year(myDate), Month(myDate), 1) To
DateSerial(Year(myDate), _
Month(myDate) + 1, 0)
Select Case Weekday(iCtr)
Case Is = CaseSat '(Does all days, remove '& does only weekdays)
'do nothing
Case Is = CaseSun '(Does all days, remove ' & does only weekdays)
'do nothing
Case Else
Application.StatusBar = D
SH.Copy after:=Sheets(Sheets.Count)
N = Sheets.Count - 3
'ActiveSheet.Range("A1").Value = D
ActiveSheet.Name = Format(iCtr, "dddd mm-dd")
Range("H4") = Format(iCtr, "mm/dd/yy")
Range("H8") = N
End Select
Next

Sheets(4).Activate
Range("D8") = N

For wCtr = 4 To Worksheets.Count
'If Worksheets(wCtr).Name = Worksheets("Setup").Name Then
'skip it
'Else
Worksheets(wCtr).Activate
Range("D8") = N
'End If
Next wCtr

Worksheets("Setup").Activate
Application.StatusBar = False
Application.ScreenUpdating = True

End Sub





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove holidays from calculation Sal Excel Worksheet Functions 9 December 29th 09 03:07 AM
change data of entire column from small case to upper case Ann Excel Worksheet Functions 1 August 16th 08 01:06 PM
Recreating the DateSerial()/Date() function Conan Kelly Excel Worksheet Functions 1 March 1st 08 04:43 AM
Changing multiple cell text from lower case to upper case Patti Excel Discussion (Misc queries) 2 January 4th 08 08:35 PM
Time/DateSerial Numeric Value Jay Excel Worksheet Functions 4 March 16th 05 03:34 AM


All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"