Hello SSGMiami,
The attached workbook contains 2 macros to automatically gray out and lock the cells that aren't in the current month of the date in cell "C3". The macro locks the worksheet but is not password protected. Password protected can be added if you want it.
Main Macro
Sub Macro1()
Dim ColLeft As Long
Dim ColRight As Long
Dim D As Integer
Dim EOM As Integer
Dim LastRow As Long
Dim Rng As Range
Dim StartRow As Long
StartRow = 7
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
ActiveSheet.Unprotect Password:=""
Cells(3, "C").Locked = False
EOM = Day(DateSerial(Year(Range("C3")), Month(Range("C3")) + 1, 0))
D = Day(Cells(3, "C"))
If D - 8 < 0 Then
ColLeft = D - 1
Else
ColLeft = D - (D - 7)
End If
If D + 8 > EOM Then
ColRight = EOM - D
Else
ColRight = EOM - (D + 7)
End If
Set Rng = Range(Cells(StartRow, "C"), Cells(LastRow, "Q"))
With Rng.Cells
.Locked = True
.Interior.ColorIndex = 15 'Light Gray
End With
Set Rng = Range(Cells(StartRow, 10 - ColLeft), Cells(LastRow, 10 + ColRight))
With Rng.Cells
.Locked = False
.Interior.ColorIndex = xlColorIndexNone
End With
ActiveSheet.Protect Password:=""
End Sub
Worksheet Event Macro
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("C3"), Target.Cells(1, 1)) Is Nothing Then
Call Macro1
End If
End Sub
Sincerely,
Leith Ross
Bookmarks