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.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top