Adding to a date but not weekend (1 Viewer)

ECEK

Registered User.
Local time
Today, 16:12
Joined
Dec 19, 2012
Messages
717
I have used this code to add days to a date and if the required date lands on a Saturday or Sunday, then move the date on by
Two days if its a Saturday and
One if its a Sunday.

the Sunday part works ie.

Date to Use: 05/03/2019 add five days gives 12/03/2019

but I am at a loss to why Saturday doesn't work?

Date to Use: 04/03/2019 add five days gives 9/03/2019 !!!! whereas it should be 11/03/2019

Could anybody point me in the right direction
Thanks for you direction.

Code:
Function addWorkDays(addNumber As Long, Date2 As Date) As Date
'********************
'Code Courtesy of
'  Paul Eugin
'********************
    Dim finalDate As Date
    Dim i As Long, tmpDate As Date
    tmpDate = Date2
    i = 1
    Do While i <= addNumber
        If Weekday(tmpDate) <> vbSaturday And Weekday(tmpDate) <> vbSunday And _
            DCount("*", "tblBankHolidays", "bankDate = " & CDbl(tmpDate)) = 0 Then i = i + 1
        tmpDate = DateAdd("d", 1, tmpDate)
    Loop
    
    addWorkDays = tmpDate
End Function
 

Users who are viewing this thread

Top Bottom