Hans,
You revised a function (thread#402239), to count the number of Sundays between a certain date range. Below is the function that you wrote for me:
You can add an extra test to the function (indicated in bold):
Function CountDaysBetween(BegDate As Date, EndDate As Date, aDay As Integer) As Integer
Dim d As Integer
If BegDate > EndDate Then Exit Function
If aDay 7 Then Exit Function
d = (EndDate – BegDate) 7
If WeekDay(EndDate, aDay) < WeekDay(BegDate, aDay) Or WeekDay(BegDate, aDay) = 1 Then
d = d + 1
End If
If WeekDay(BegDate) = 1 Then
d = d + 1
End If
CountDaysBetween = d
End Function
Is there a formula in Excel that could do the same thing?