Calculating Working Days....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • josephsimonbenn
    New Member
    • Apr 2010
    • 32

    #1

    Calculating Working Days....

    I need to calculate the number of business days employees work in each month using vba. The problem is, some employees work 3 days, some 4 and some 5.

    So i want to be able to turn on/off the days via checkboxes.

    I found this code... which will basically count the days that aren't saturday or sunday, but Can someone modify this code so that the days are only counted if the checkboxes are selected....

    Checkboxes are called: ChkSunday, ChkMonday, ChkTuesday, ChkWednesday, ChkThursday, ChkFriday, ChkSaturday.

    Code:
    Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
    On Error GoTo Err_WorkingDays
    
    Dim intCount As Integer
    
    intCount = 0
    Do While StartDate <= EndDate
    
    Select Case Weekday(StartDate)
    Case Is = 1, 7
    intCount = intCount
    Case Is = 2, 3, 4, 5, 6
    intCount = intCount + 1
    End Select
    StartDate = StartDate + 1
    Loop
    WorkingDays = intCount
    
    Exit_WorkingDays:
    Exit Function
    
    Err_WorkingDays:
    Select Case Err
    
    Case Else
    MsgBox Err.Description
    Resume Exit_WorkingDays
    End Select
    
    End Function
    I attempted to do it myself using an array but it didnt work out!!

    Pleeeeeeeeeeeea aaaaaaaaseeeeee eeee help :) Cheers.
Working...