Protect a row based on a date

jmulvane

New Member
Joined
Nov 16, 2005
Messages
1
Hello and thanks for any help,

I have a spreadsheet with a date column and several other columns for that day's data input so that each day has its own row. What I would like to do is protect the data from previous days so it will not be accidentally deleted. In other words, If today > date in column A than that row is locked and protected.

I am new to this site, but I have looked through several threads and can't seem to find a solution to what I would like to do. I am a novice with macros, but am comfortable trying to mess around with them, any help is greatly appreciated.
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Try this; it should go in the ThisWorkbook module and will run whenever the workbook is opened:

Code:
Private Sub Workbook_Open()
Dim ws As Worksheet, c As Range

Set ws = Sheets("Sheet1")

With ws
    .Unprotect 'unprotect sheet
    
    'check each cell in column A
    For Each c In .Range("A2", .Range("A65536").End(xlUp))
        If c.Value < Date Then 'if value in cell is < today
            c.EntireRow.Locked = True 'lock entire row
        Else 'otherwise
            c.EntireRow.Locked = False 'unlock entire row
        End If
    Next c
    .Protect 'protect sheet
End With

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,032
Messages
5,569,764
Members
412,291
Latest member
marypolitan
Top