Disable editing of offset cells.

rdoulaghsingh

Board Regular
Joined
Feb 14, 2021
Messages
105
Office Version
  1. 365
Platform
  1. Windows
Is there a line of code I can add to the script below to lock/disable the offset cells form being edited without having to lock/protect the entire workbook?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count = 1 Then
        If Not Intersect(Target, Range("C3:C13,C18:C28")) Is Nothing Then
            Application.EnableEvents = False
            If Target.Value = "N/A" Then
                With Target(1, 0)
                    .Value = "(N/A)"
                    With .Interior
                        .Pattern = xlLightDown
                        .TintAndShade = 0
                        .PatternTintAndShade = 0
                    End With
                End With
            Else
                With Target(1, 0)
                    .Value = ""
                    With .Interior
                        .Pattern = xlPatternNone
                        .TintAndShade = 0
                        .PatternTintAndShade = 0
                    End With
                End With
            End If
            Application.EnableEvents = True
        End If
    End If
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Nevermind. Thanks! I found a workaround for this by using a message box and then offsetting the active cell selection.
 
Upvote 0
Glad to hear you got the solution.

Do you mind posting your solution code? Then it is perfectly fine to mark your post as the solution to help future readers.
 
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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