Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have two dates from 9 Nov 2007 to 3 Dec 2007.
I want to calculate workdays for this mentained range & getting result as 17 Days by putting the formula as networkdays. Problem is that I want to consider 6 working days instead of 5 working days. How to get results?? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try:
Sub Test() MsgBox GetWorkdays("9 Nov 2007", "3 Dec 2007") End Sub Function GetWorkdays(FirstDate As Date, LastDate As Date) As Integer Dim i As Integer, ii As Integer ii = 0 For i = 0 To (LastDate - FirstDate) If Weekday(FirstDate + i) < 1 Then ii = ii + 1 Next GetWorkdays = ii End Function Regards, Greg |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, it works...
But the details I actualy need to fill in Excel worksheet is as follows: Start Date: 9 Nov 2007 End Date : 3 Dec 2007 1) Sundays on : dd-mm-yy , dd-mm-yy,........ 2) Holidays on : ........ 3) Total Working days : ?? (by considering Monday to saturday as working Days) I am to too exposed to programing, so please provide me the simplest way to get the results that I need. Thanks in advance for your help. *Nilay* "Greg Wilson" wrote: Try: Sub Test() MsgBox GetWorkdays("9 Nov 2007", "3 Dec 2007") End Sub Function GetWorkdays(FirstDate As Date, LastDate As Date) As Integer Dim i As Integer, ii As Integer ii = 0 For i = 0 To (LastDate - FirstDate) If Weekday(FirstDate + i) < 1 Then ii = ii + 1 Next GetWorkdays = ii End Function Regards, Greg |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You might also try in the worksheet function ng for another option.
Function example:- 1. Put the 1st date in cell A1 2. Put the last date in cell A2 3. Put in cells A3 to A12 the holidays 4. Enter this in cell C1: =GetWorkdays(A1, A2, A3:A12) Function GetWorkdays(FirstDate As Date, LastDate As Date, _ Optional Hols As Variant) As Integer Dim i As Integer, ii As Integer, wkdys As Integer Dim dy As Date Dim f As Boolean wkdys = 0 For i = 0 To (LastDate - FirstDate) dy = CDate(FirstDate + i) If Weekday(dy) < 1 Then f = False If Not IsMissing(Hols) Then For ii = 1 To Hols.Count If Len(Hols(ii)) = 0 Then Exit For If CDate(Hols(ii)) = dy Then f = True Exit For End If Next End If If Not f Then wkdys = wkdys + 1 End If Next GetWorkdays = wkdys End Function Greg |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear Greg,
Thanks. This function is working absolutely fine. With Regards, Nilay "Greg Wilson" wrote: You might also try in the worksheet function ng for another option. Function example:- 1. Put the 1st date in cell A1 2. Put the last date in cell A2 3. Put in cells A3 to A12 the holidays 4. Enter this in cell C1: =GetWorkdays(A1, A2, A3:A12) Function GetWorkdays(FirstDate As Date, LastDate As Date, _ Optional Hols As Variant) As Integer Dim i As Integer, ii As Integer, wkdys As Integer Dim dy As Date Dim f As Boolean wkdys = 0 For i = 0 To (LastDate - FirstDate) dy = CDate(FirstDate + i) If Weekday(dy) < 1 Then f = False If Not IsMissing(Hols) Then For ii = 1 To Hols.Count If Len(Hols(ii)) = 0 Then Exit For If CDate(Hols(ii)) = dy Then f = True Exit For End If Next End If If Not f Then wkdys = wkdys + 1 End If Next GetWorkdays = wkdys End Function Greg |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Calculate working days but change working week | Excel Discussion (Misc queries) | |||
Calculate elapsed working days | Excel Discussion (Misc queries) | |||
calculate number of working days | Excel Worksheet Functions | |||
Is there a way to calculate business working days between dates i. | Excel Worksheet Functions | |||
how do I calculate the days between dates? | Excel Discussion (Misc queries) |