Autofill a range with weekdays and exclude holidays

Eric Carolus

Board Regular
Joined
Sep 17, 2012
Messages
64
Office Version
2016
Platform
Windows
Hallo good people

I am doing a project and the line below autofill a range for me (it works just fine) with weekdays.

ActiveCell.AutoFill Destination:=Range(ActiveCell.Address & ":" & "B" & Days + 4), Type:=xlFillWeekdays

However, I have a table somewhere called Holidays (with dates) and I wish to somehow add some code
to the line so Holiday dates will be excluded from the autofill.

Can someone help or point me in the right direction, please?

Thanks

Eric
 

JustynaMK

Well-known Member
Joined
Aug 28, 2016
Messages
506
Office Version
365, 2013
Platform
Windows
Hi Eric,

I don't think it's possible with AutoFill, but you can try using the following code:

Code:
Sub FillWorkdays()
    Dim lngDays             As Long
    
    For lngDays = 1 To 4
        ActiveCell.Offset(lngDays, 0).Formula = "=WORKDAY(" & ActiveCell.Address & "," & lngDays & ",[COLOR=#ff0000]$G$4:$G$10[/COLOR])"
    Next lngDays


End Sub
This one assumes that your holidays are stored in cells G4:G10.

Hope it helps.
 

JustynaMK

Well-known Member
Joined
Aug 28, 2016
Messages
506
Office Version
365, 2013
Platform
Windows
You're welcome! Take care.
 

Forum statistics

Threads
1,082,501
Messages
5,365,942
Members
400,863
Latest member
kimtid

Some videos you may like

This Week's Hot Topics

Top