I am confused why this VBA code is behaving this strangely:
I have a sheet with a range of dates in the first row. Now I want to delete the whole column if the date is a saturday/sunday or a bank holiday:
holidays = Array("01.01.2022", "15.04.2022", "18.04.2022", "01.05.2022", "26.05.2022", "06.06.2022", "16.06.2022", "03.10.2022", "25.12.2022", "26.12.2022")
Dim holiday As Variant
For Each c In Range("B1", Range("B1").End(xlToRight)).Cells
For Each holiday In holidays
If c.Value = CDate(holiday) Then
c.EntireColumn.Delete
End If
Next holiday
If Weekday(c.Value, 2) > 5 Then
c.EntireColumn.Delete
End If
Next c
If I run this macro it deletes all Saturdays only, if I run it a second time it deletes all Sundays too.
But why does it not delete all Saturdays and Sundays in the first run?