Amount of holidays within a range of dates

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,

I am stuck with following.

I got a function wich returns a boolean when a date ist a public holiday.. i found this code on the net.. works fine ...
However now I like to create a new function which returns the amount of hoidays within a range of dates.

VBA Code:
Function HolidaysWithinRange(datStart As Date, datEnd As Date) As Integer
    Dim lngDays As Long
    Application.Volatile
    
    Dim lngCount As Long
    
    For lngDays = 1 To CLng(datEnd - datStart)
        
        If lngDays = 1 Then
            Feiertag (datStart)
        
        Else
            Feiertag (datStart) + lngDays           
        End If 
    
    If Feiertag(datDate) = True Then
        HolidaysWithinRange =         HolidaysWithinRange + 1   
    End If
    
    Next lngDays


End Function

The function "Feiertag" requires only one parameter a date and retourns true or false if the date is a holiday

But I like to get the amount of holidays out from the function above but somehow not really have luck to figure it out.

Can someone put me in the right direction please?

Many thanks

SW
 
VBA Code:
Function HolidaysWithinRange(datStart As Date, datEnd As Date) As Integer
    Dim lngDays As Date
    Application.Volatile
    For lngDays = datStart To datEnd
        If Feiertag(lngDays) = True Then
            HolidaysWithinRange = HolidaysWithinRange + 1
        End If
    Next lngDays
End Function

Function Feiertag(Datum As Date) As Boolean 'GMG-CC.de
...
Hi Mart37,

many thanks yes it works now great job!!!

Nice greetings

SW
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top