PDA

View Full Version : Show messagebox if user selects locked cells



keilah
04-02-2008, 03:19 AM
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveSheet.ProtectContents = True Then
If ActiveCell.Locked = True Then
MsgBox "Select cells are locked"
End If
End If
End Sub

Hi experts

I have the following vba code but when i add it to the worksheet and lock the cells i cannot get the message to apear if the users trys to click into a locked range of cells.......

not sure what i am doing wrong

Bob Phillips
04-02-2008, 04:16 AM
It works fine for me although the code should be



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Me.ProtectContents = True Then
If Target.Locked = True Then
MsgBox "Select cells are locked"
End If
End If
End Sub


Did you put the code in the worksheet code module?