Lock Cells outside of dates

Dazzybeeguy

Board Regular
Joined
Jan 6, 2022
Messages
111
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have a column of dates is Column A

In C1 I want to put a Start Date
In E1 I want to put a End Date

Is their a way to just unlock cells in Column A that are = to or between those dates ?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Locked cell not affected unless you protect the sheet, how you input Start Date and End Date if sheet is protected?
 
Upvote 0
Put this on your Worksheet Code Environment :

VBA Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 Or Target.Column = 5 And Target.Row = 1 Then
        Dim dtStart, dtEnd As Date
        
        dtStart = Me.Range("C1").Value
        dtEnd = Me.Range("E1").Value
        
        If IsDate(dtStart) And IsDate(dtEnd) Then
            Dim arrData As Variant
            Dim iLast, i As Long
            
            iLast = Me.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            
            arrData = Me.Range("A1:A" & iLast).Value
            
            Me.Unprotect
            
            For i = LBound(arrData) To UBound(arrData)
                If arrData(i, 1) >= dtStart And arrData(i, 1) <= dtEnd Then
                    Me.Range("A" & i).Locked = False
                Else
                    Me.Range("A" & i).Locked = True
                End If
            Next i
            
            Me.Protect
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,573
Messages
6,173,138
Members
452,501
Latest member
musallam

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