Excel 2010-2019
Excel 2007
Excel 2003
Tips & Tricks
Excel Forum
Course Index CIG Excel Book
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List


Number of Work Days
Use NETWORKDAYS to count the number of work days between two dates
Create a custom function in VBA to handle odd situations

Q: I need to calculate the number of work days between two dates. I understand the NETWORKDAYS function allows me to calculate Monday thru Friday, but we also work on Saturdays. How can I count the number of days between two dates, but exclude all of the Sundays only?
A: Very good question. Yes, you can use NETWORKDAYS if you only need to worry about excluding Saturdays, Sundays, and a list of holidays. However, if you have a custom requirement like yours, you'll need to write your own function using VBA. Here is the function I wrote.

Note that in the video, the end of the first line of code says "as Date" but it should be "as Long". It works fine in both cases, but you should return a Long instead of a Date value.

Public Function MyWorkDays(D1 As Date, D2 As Date) As Long
  DayCount = 0
  For X = D1 To D2
    D = Weekday(X) '1=sun, 7=sat
    If D <> 1 Then DayCount = DayCount + 1
  Next X
  MyWorkDays = DayCount
End Function


Here is a FREE video tutorial that shows you how to set up this function step-by-step:
 Click here to view the FREE video


By Richard Rost   Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost
Click here to sign up for more FREE tips


Check out these other pages that may be of interest to you:

1/27/2023Math in Fields
12/12/2022Tax Brackets
12/9/2022Double Lookup
10/24/2022Follow Hyperlink
9/17/2022Very Hidden
7/26/2022Lottery Numbers 2
7/22/2022Lottery Numbers


The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
My Account
My Courses
Lost Password
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Customer Support
Web Site Tour
Consulting Services
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn
Copyright 2023 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 2/6/2023 2:47:41 AM.