By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

Calculating Working Days....

P: 32
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.

Expand|Select|Wrap|Line Numbers
  1. Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
  2. On Error GoTo Err_WorkingDays
  3.  
  4. Dim intCount As Integer
  5.  
  6. intCount = 0
  7. Do While StartDate <= EndDate
  8.  
  9. Select Case Weekday(StartDate)
  10. Case Is = 1, 7
  11. intCount = intCount
  12. Case Is = 2, 3, 4, 5, 6
  13. intCount = intCount + 1
  14. End Select
  15. StartDate = StartDate + 1
  16. Loop
  17. WorkingDays = intCount
  18.  
  19. Exit_WorkingDays:
  20. Exit Function
  21.  
  22. Err_WorkingDays:
  23. Select Case Err
  24.  
  25. Case Else
  26. MsgBox Err.Description
  27. Resume Exit_WorkingDays
  28. End Select
  29.  
  30. End Function
I attempted to do it myself using an array but it didnt work out!!

Pleeeeeeeeeeeeaaaaaaaaaseeeeeeeeee help :) Cheers.
Apr 29 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.