Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi All,
Please help to modify the code to make the column appearance change - the font to be red if the column date falls to holiday ; interior change to some color if it is weekend; and font to be black if it is weekdays.
Please help to modify the code to make the column appearance change - the font to be red if the column date falls to holiday ; interior change to some color if it is weekend; and font to be black if it is weekdays.
VBA Code:
Public Function IsHolWeekend(InputDate As Date) As Boolean
Dim vLastRow As Long
Dim vR1 As Range
With ThisWorkbook.Worksheets("Data")
vLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
For Each vR1 In .Range("A2:A" & vLastRow)
If Day(InputDate) = Day(vR1) And _
Month(InputDate) = Month(vR1) And _
Year(InputDate) = Year(vR1) Then
IsHolWeekend = 1
ElseIf Weekday(InputDate) = 1 Or Weekday(InputDate) = 7 Then
IsHolWeekend = 2
Else
IsHolWeekend = 0
'Exit Function
End If
Next vR1
End With
End Function
Sub HolidayandWeekend19()
Dim vRng As Range
Dim vLastRow As Long
Dim vRngCol As Range
With ThisWorkbook.ActiveSheet
vLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set vRng = Range("C1", Range("AL" & vLastRow))
For Each vRngCol In vRng.Columns
If IsHolWeekend(vRngCol.Cells(1)) = 1 Then
With Columns(vRngCol.Column)
.Font.Color = vbRed
End With
ElseIf IsHolWeekend(vRngCol.Cells(1)) = 2 Then
With Columns(vRngCol.Column)
.Interior.Color = RGB(255, 245, 230)
End With
Else
With Columns(vRngCol.Column)
.Font.Color = vbBlack
End With
End If
Next vRngCol
End With
End Sub