In my VBA code below, when I double click onany cell in the range A2:G52,
The code does not run and I get a warning message 'The cell or chart you are trying to change is in a protected sheet.
Can you please help me to resolve this issue.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim ws As Worksheet
Dim formulaReference1 As String
    ' Check if the double-click target is I3:I51
    If Not Intersect(Target, Range("I3:I51")) Is Nothing Then
        ' Get the text value from the clicked cell
        formulaReference1 = Target.Value
        If Len(formulaReference1) > 0 Then
            ' Remove any leading apostrophe
            If Left(formulaReference1, 1) = "'" Then
                formulaReference1 = Mid(formulaReference1, 2)
            End If
            ' Split at "!"
            Dim formulaParts1 As Variant
            formulaParts1 = Split(formulaReference1, "!")
            If UBound(formulaParts1) >= 1 Then
                Dim worksheetName1 As String, cellAddress1 As String
                worksheetName1 = formulaParts1(0)
                cellAddress1 = formulaParts1(1)
                ' Get the target worksheet
                On Error Resume Next
                Set ws = ThisWorkbook.Worksheets(worksheetName1)
                On Error GoTo 0
                ' If the sheet exists, activate it and select the cell
                If Not ws Is Nothing Then
                    Cancel = True
                    ws.Activate
                    ws.Range(cellAddress1).Select
                End If
            End If
        End If
        Exit Sub
    End If

        Select Case Target.Value
            Case "Day": Set ws = ThisWorkbook.Sheets("Day")
            Case "Week": Set ws = ThisWorkbook.Sheets("Week")
            Case "Fortnight": Set ws = ThisWorkbook.Sheets("Fortnight")
            Case "Month": Set ws = ThisWorkbook.Sheets("Month")
            Case "QtrYear": Set ws = ThisWorkbook.Sheets("QtrYear")
            Case "HalfYear": Set ws = ThisWorkbook.Sheets("HalfYear")
            Case "Year": Set ws = ThisWorkbook.Sheets("Year")
        End Select
    If Not ws Is Nothing Then
    Cancel = True
        ws.Activate
            Exit Sub
    End If

            Dim TargetCell As Range
            Set TargetCell = ActiveCell
            If Not Intersect(TargetCell, Range("A2:G52")) Is Nothing Then
            With ThisWorkbook.Sheets("Planner")
            .Unprotect Password:="edit"

            Dim formulaReference As String
            Dim worksheetName As String
            Dim cellAddress As String
            Dim destinationWorksheet As Worksheet

            ' Read the formula from the target cell
            formulaReference = TargetCell.Formula

            ' Check if the formula uses INDIRECT
            If Left(formulaReference, 9) = "=INDIRECT(" Then
                ' Extract the reference inside INDIRECT
                formulaReference = Mid(formulaReference, 10, Len(formulaReference) - 10) ' Remove '=INDIRECT('
                formulaReference = Replace(formulaReference, """", "") ' Remove double quotes
                formulaReference = Replace(formulaReference, "'", "") ' Remove any single quotes
                formulaReference = Trim(formulaReference) ' Clean up spaces

                ' Check if it's a cell reference (like $T$2)
                If Left(formulaReference, 1) = "$" Then
                    ' Use Application.Evaluate to get the value of the referenced cell.
                    Dim targetCellValue As String
                    targetCellValue = Application.Evaluate(formulaReference) ' This will fetch the content of the referenced cell

                    If InStr(targetCellValue, "!") > 0 Then ' Ensure it contains a worksheet reference
                        Dim formulaParts As Variant
                        formulaParts = Split(targetCellValue, "!")

                        If UBound(formulaParts) >= 1 Then
                            worksheetName = formulaParts(0) ' Get worksheet name
                            cellAddress = formulaParts(1) ' Get cell address

                            ' Activate the destination worksheet and select the cell
                            Set destinationWorksheet = ThisWorkbook.Worksheets(worksheetName)
                            destinationWorksheet.Unprotect Password:="edit"
                            destinationWorksheet.Activate
                            destinationWorksheet.Range(cellAddress).Select
                        End If
                    End If
                End If
            End If
        End With
    End If
    ThisWorkbook.Sheets("Planner").Protect Password:="edit"
End Sub