Disable editing of offset cells.

rdoulaghsingh

Board Regular
Joined
Feb 14, 2021
Messages
55
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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

rdoulaghsingh

Board Regular
Joined
Feb 14, 2021
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Nevermind. Thanks! I found a workaround for this by using a message box and then offsetting the active cell selection.
 

smozgur

BatCoder
Joined
Feb 28, 2002
Messages
1,403
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,478
Messages
5,636,570
Members
416,925
Latest member
malamutus

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