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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,114
Messages
5,835,462
Members
430,358
Latest member
zzc1128

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
Top