A break through Maintain your holidays in a worksheet. (either maintain them in ascending order or order them through code depending on the frequency of changes in holidays)
In the function just count the holidays falling between start_date and end_date simply deduct them from the getworkdays. Regards, Kishan Reddy, K On Oct 18, 5:42 pm, "me!" <infinite.space....@googlemail.com> wrote: > Hi, I have the following code that calculates the number of days > (excluding Sundays) between two dates, and ideally I'd like to add > another parameter to my function to allow me to exclude non-working > days (in a similar way to the in-built NETWORKDAYS function - - > NETWORKDAYS(start_date,end_date,holidays) > > Can anyone help? . . . Many thanks, J > > 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 = 1 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 -- ---------------------------------------------------------------------------------- Some important links for excel users: 1. Follow us on TWITTER for tips tricks and links : http://twitter.com/exceldailytip 2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310 3. Excel tutorials at http://www.excel-macros.blogspot.com 4. Learn VBA Macros at http://www.quickvba.blogspot.com 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to excel-macros@googlegroups.com <><><><><><><><><><><><><><><><><><><><><><> Like our page on facebook , Just follow below link http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts