Hi Lionel
This code is in the attached:
In 12-Mar Worksheet Module
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("D3")) Is Nothing Then
Call cmdSAT_SUN_Click
End If
End Sub
In a General Module
Option Explicit
Sub cmdSAT_SUN_Click()
Dim wsActive As Worksheet
Dim rngDay As Range
Dim c As Range
Dim LC As Long
Dim strDate As String
Dim LR As Long
Dim myCol As Long
Dim cel As Range
If ActiveSheet.Name = "TEMPLATE" Then Exit Sub
Set wsActive = ActiveSheet
Application.ScreenUpdating = False
With wsActive
LC = .Cells(5, .Columns.Count).End(xlToLeft).Column 'Row 5
LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
' Sat & Sun Columns have moved so, find the first Column in Row 6 with a Blue Cell
For Each cel In .Range(.Cells(6, 10), (.Cells(6, LC)))
If cel.Interior.Color = &HFFFFC0 Then
myCol = cel.Column
Exit For
End If
Next cel
' Filter on Blue Cells
On Error Resume Next 'In case there are no Blue Cells
.Range(.Cells(4, myCol), (.Cells(LR, myCol))).AutoFilter Field:=1, Criteria1:=&HFFFFC0, _
Operator:=xlFilterCellColor
' Make them all White
.Range(.Cells(4, 10), (.Cells(LR, LC))).Offset(1, 0).SpecialCells(xlCellTypeVisible).Interior.Color = vbWhite
.AutoFilterMode = False
On Error GoTo 0
' Now filter on the White Cells
.Range(.Cells(4, 10), (.Cells(LR, LC))).AutoFilter Field:=1, Criteria1:=RGB(255, _
255, 255), Operator:=xlFilterCellColor
End With
' Find the Sat and Sun Cells and make them Blue
Set rngDay = wsActive.Range("J5:" & Cells(5, LC).Address)
For Each c In rngDay
strDate = Format(c, "ddd")
Select Case strDate
Case Is = "Sat", "Sun"
Range(Cells(6, c.Column), Cells(LR, c.Column)).SpecialCells(xlCellTypeVisible).Interior.Color = &HFFFFC0
End Select
Next c
wsActive.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
Let me know of issues.
Bookmarks