Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to calculate 6 working days between two dates

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default How to calculate 6 working days between two dates

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to calculate 6 working days between two dates

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default How to calculate 6 working days between two dates

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to calculate 6 working days between two dates

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
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
Calculate working days but change working week SamB Excel Discussion (Misc queries) 1 September 1st 08 09:17 PM
Calculate elapsed working days RUSH2CROCHET Excel Discussion (Misc queries) 6 March 9th 06 08:36 PM
calculate number of working days philc Excel Worksheet Functions 2 June 1st 05 07:48 AM
Is there a way to calculate business working days between dates i. hjyoungii Excel Worksheet Functions 2 February 23rd 05 04:25 PM
how do I calculate the days between dates? stucklady! Excel Discussion (Misc queries) 7 February 12th 05 04:39 PM


All times are GMT +1. The time now is 09:33 PM.

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"