Loking Cells by Date
Oops! I forgot the hightlight part.
Sub LockDates()
Const wksName As String = "Sheet1"
Dim cell As Range
Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
With cell
If .Value = Date Then
.Locked = False
.Interior.Color = 3
Else
.Locked = True
.Interior.Color = xlNone
End If
End With
Next cell
Sheets(wksName).Protect Password:=""
End Sub
--
Cheers,
Ryan
"RyanH" wrote:
This should work for you! I took the liberty of highlighting the unlocked
cells yellow. This will maximize readilbilty. If you don't want that then
just delete it out of the code.
Note: The sheet has to be protected for the Lock Property of the cells to
be active.
Sub LockDates()
Const wksName As String = "Sheet1"
Dim cell As Range
Sheets(wksName).Unprotect Password:=""
For Each cell In Sheets(wksName).UsedRange
If cell.Value = Date Then
cell.Locked = False
Else
cell.Locked = True
End If
Next cell
Sheets(wksName).Protect Password:=""
End Sub
If this helps please click "Yes" below.
--
Cheers,
Ryan
"Daniel" wrote:
I have a chart where information is filled in every day. I would like the
cells to be available only "today." How do I have the cells lock for all
days that have passed, aas well as all of the days in the future?
|