best way to protected cells in column A

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
339
Office Version
  1. 2016
Platform
  1. Windows
I have a sheet where the cells in col A needs to be protected against selecting, and against changing.

I don't want to protect the sheet, so I'm looking at the two methods below.

Which do you recommend ?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim j As Integer
j = Target.Column

If j = 1 Then
  Application.EnableEvents = False  
  Application.Undo
  Application.EnableEvents = True
  MsgBox "No change allowed"
End If
End Sub

VBA Code:
OR

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim j As Integer
j = Target.Column
    
Application.EnableEvents = False

If j = 1 Then
    Cells(1,2).Select
  MsgBox "No change allowed"
End If

Application.EnableEvents = True

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you prevent the user from even selecting a cell in column A - it would be impossible for them to change any cell in column A. Therefore, the SelectionChange code would be the way to go. I might shorten it a bit:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column = 1 Then
        Cells(1, 2).Select
        MsgBox "Cannot select/change cells in column A"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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