#1   Report Post  
Posted to microsoft.public.excel.setup
external usenet poster
 
Posts: 2
Default changing weekend days

Hi
I am trying to use the networkdays but I need to change the weekend days
from Saturday and Sunday to Thursday and Friday

  #2   Report Post  
Posted to microsoft.public.excel.setup
external usenet poster
 
Posts: 3,440
Default changing weekend days

Here's a VBA solution from Ron Rosenfeld

--
Kind regards,

Niek Otten
Microsoft MVP - Excel
' ===========================
' Ron Rosenfeld
' Copied form Google's Newsgroup Archives April 27, 2006

Function NWrkDays(StartDate As Date, EndDate As Date, _
Optional Holidays As Range = Nothing, _
Optional WeekendDay_1 As Integer = 1, _
Optional WeekendDay_2 As Integer = 7, _
Optional WeekendDay_3 As Integer = 0) As Long
' Sunday = 1; Monday = 2; ... Saturday = 7


'credits to Myrna


Dim i As Long
Dim Count As Long
Dim H As Variant
Dim w As Long
Dim SD As Date, ED As Date
Dim DoHolidays As Boolean
Dim NegCount As Boolean


DoHolidays = Not (Holidays Is Nothing)


SD = StartDate: ED = EndDate
If SD ED Then
SD = EndDate: ED = StartDate
NegCount = True
End If


w = Weekday(SD - 1)
For i = SD To ED
Count = Count + 1
w = (w Mod 7) + 1
Select Case w
Case WeekendDay_1, WeekendDay_2, WeekendDay_3
Count = Count - 1
Case Else
If DoHolidays Then
If IsNumeric(Application.Match(i, Holidays, 0)) Then _
Count = Count - 1
End If
End Select
Next i
If NegCount = True Then Count = -Count
NWrkDays = Count
End Function


Function WrkDay(StartDate As Date, ByVal NumDays As Long, _
Optional Holidays As Range = Nothing, _
Optional WeekendDay_1 As Integer = 1, _
Optional WeekendDay_2 As Integer = 7, _
Optional WeekendDay_3 As Integer = 0) As Date


' Sunday = 1; Monday = 2; ... Saturday = 7


Dim i As Long
Dim TempDate As Date
Dim Stp As Integer
Dim NonWrkDays As Long
Dim temp As Long, SD As Date, ED As Date


Stp = Sgn(NumDays)


'Add NumDays
TempDate = StartDate + NumDays


'Add Non-Workdays


Do While Abs(NumDays) < temp
SD = Application.WorksheetFunction.Min(StartDate + Stp, TempDate)
ED = Application.WorksheetFunction.Max(StartDate + Stp, TempDate)


temp = NWrkDays(SD, ED, Holidays, WeekendDay_1, WeekendDay_2, WeekendDay_3)
TempDate = TempDate + NumDays - Stp * (temp)
Loop


WrkDay = TempDate
End Function
' ==========================

"Otaibi" wrote in message ...
| Hi
| I am trying to use the networkdays but I need to change the weekend days
| from Saturday and Sunday to Thursday and Friday
|


  #3   Report Post  
Posted to microsoft.public.excel.setup
external usenet poster
 
Posts: 10,593
Default changing weekend days

=end_date-start_date+1-INT((WEEKDAY(start_date-1)+end_date-start_date)/7)

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Otaibi" wrote in message
...
Hi
I am trying to use the networkdays but I need to change the weekend days
from Saturday and Sunday to Thursday and Friday



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
Formula to Remove Weekend Days Tom Excel Discussion (Misc queries) 1 May 24th 06 04:31 PM
add days without adding weekend brian thompson3001 via OfficeKB.com New Users to Excel 11 March 8th 06 05:02 PM
Due date excluding weekend days Jfilbig Excel Worksheet Functions 5 February 5th 06 06:45 PM
Weekend days other than Sat Sun rkk Excel Worksheet Functions 15 January 25th 05 02:31 AM
Re-assigning weekend days in "Networkdays" Function sts75 Excel Discussion (Misc queries) 0 November 26th 04 10:45 AM


All times are GMT +1. The time now is 01:53 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"