Hi,

I am trying to create a desk booking tool which only allows bookings to be made using a defined list up to 30 days in the future. I have the below code, pieced together using other codes, as I am not an expert on VBA, but I cannot seem to get it to work as I would like.

I am unable to upload anything from the machine I am using so having to improvise a little

Essentially, I would like to unlock rows within the range E19:AA448 up until a date 30 days in the future (this date can be input into cell A18 using =TODAY()+30). For example, the sheet starts on 6/5/24, if it was that date, I would like to allow only rows within the defined range to be selected as long as the dates within the range A19:A448 doesn't exceed 30 days after the date of 6/5/24, which will be a rolling date based on the current date each time it is opened. Within this example, this would open up rows until 5/6/24.

Code:
Option Explicit
Dim blnUnlockedAllCells As Boolean
Private Sub Workbook_Open()
    
    Dim wksTarget           As Worksheet
    Dim rngDate             As Range
    Dim rngData             As Range
    Dim r                   As Long
    Dim LastRow             As Long
    Dim LastCol             As Long
    Dim blnUnlockedAllCells As Boolean
    
    Const Pwd               As String = "pwd"
    
    Set wksTarget = ThisWorkbook.Worksheets("Vertical")
    Set rngData = wksTarget.Range("$A$19:$AA$448")
    
    If Not blnUnlockedAllCells Then
        wksTarget.Unprotect Password:=Pwd
        wksTarget.Cells.Locked = True
        rngData.Locked = False
        wksTarget.Protect Password:=Pwd, userinterfaceonly:=True
        blnUnlockedAllCells = True
    End If
    
    For r = 19 To 448
        If CDate(rngData(r, 1)) <= Date + 30 Then
            On Error Resume Next
            rngData.Rows(r).Locked = True
            On Error GoTo 0
        End If
    Next
    
End Sub