PDA

View Full Version : display differnt cell protection message



wilg
12-30-2011, 03:23 PM
Is there a way to change to message when someone is trying to key into a protected cell other than the automatic message? I would like to customize my own message if they are trying to change a protected cell.

marreco
12-31-2011, 03:52 AM
hi...

I have an example I just like to post what you want ....
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewValue As Variant, OldValue As Variant
If Target.Count > 1 Then Exit Sub
'Say you want to work with the range A1:F10
If Not Intersect(Target, Range("A1:F10")) Is Nothing Then
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo
OldValue = Target.Value
If OldValue <> "" Then
MsgBox "place your message here.", 16, "Células Bloqueadas"
Target.Value = OldValue
Else
Target.Value = NewValue
End If
Application.EnableEvents = True
End If
End Sub

mikerickson
12-31-2011, 03:58 AM
This can be done with data validation.

Put formulas in the cells.
Select a cell and set data Validation to the formula =FALSE, uncheck the Ignore Blanks box and set the message of your choice.

Copy this validation to any cells that you want protected from user entry. (it does not protect against paste.)

haquangduy
01-05-2012, 12:49 AM
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewValue As Variant, OldValue As Variant
If Target.Count > 1 Then Exit Sub
'Say you want to work with the range A1:F10
If Not Intersect(Target, Range("A1:F10")) Is Nothing Then
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo OldValue = Target.Value
If OldValue <> "" Then
MsgBox "place your message here.", 16, "Células Bloqueadas"
Target.Value = OldValue
Else
Target.Value = NewValue
End If
Application.EnableEvents = True
End If
End Sub