Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Gerardo
 
Posts: n/a
Default DIAS.LAB function problem

Hi there,
I have to calculate the days between two date. But between monday to
saturday. The DIAS.LAB function calculate the total days between monday and
friday and that is my problem, I have to include saturday.
I really want to know is there another function or how can resolve this
problems. Thansk in advance
  #2   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default DIAS.LAB function problem

On Mon, 31 Oct 2005 09:04:21 -0800, "Gerardo"
wrote:

Hi there,
I have to calculate the days between two date. But between monday to
saturday. The DIAS.LAB function calculate the total days between monday and
friday and that is my problem, I have to include saturday.
I really want to know is there another function or how can resolve this
problems. Thansk in advance



To calculate days between dates, without taking into account weekends at all,
merely subtract one from the other:

A1: =StartDate
A2: =EndDate

Days between = EndDate-StartDate

You may need to add '1' to the total as the NetWorkdays function is INclusive
and merely subtracting does not include StartDate.

If you are looking for a function similar to NetWorkdays, but where Sunday is
the only weekend day, then:

You can use this formula from Bob Phillips (you'll have to translate it to your
language):

=SUMPRODUCT(INT((MAX(end_date,start_date)-WEEKDAY(MAX(end_date,start_date)+1
-{2;3;4;5;6;7})-MIN(end_date,start_date)+8)/7))
-SUMPRODUCT(ISNUMBER(MATCH(WEEKDAY(holidays),{2;3;4 ;5;6;7},0))*(holidays=MI
N(end_date,start_date))*(holidays<=MAX(end_date,st art_date)))

Or you can use this UDF which should translate automatically:

To use the UDF, enter a formula in the form:

=NWD(StartDate, EndDate, [holidays])

[holidays] is an optional argument referring to a list of holiday dates not to
be included.

To enter the UDF, <alt<F11 opens the VB Editor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code below into the window that opens. The UDF actually allows you to specify
your workweek as you wish, but I have entered the coding for a Sunday only
weekend. So you should not have to make any changes.

============================
Option Explicit

Function NWD(StartDate As Date, EndDate As Date, _
Optional Holidays As Range = Nothing, _
Optional WeekendDay_1 As Integer = 1, _
Optional WeekendDay_2 As Integer = 0, _
Optional WeekendDay_3 As Integer = 0, _
Optional WeekendDay_4 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, WeekendDay_4
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
NWD = Count
End Function
==================================


--ron
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
count function problem nkidd Excel Worksheet Functions 4 July 7th 05 08:55 PM
Lookup function problem (kg) greencecil Excel Worksheet Functions 3 July 1st 05 04:54 PM
Problem with function "Worksheet_Change" konpego Excel Worksheet Functions 0 June 23rd 05 05:46 AM
Problem adding a range using Sumif function. vrk1 Excel Worksheet Functions 2 June 22nd 05 06:05 PM
Need a ISWorkday Function -- Any Ideas Mark Excel Worksheet Functions 5 March 29th 05 01:58 AM


All times are GMT +1. The time now is 04:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"