Keep Cell Unlocked but Don't Allow User to Change the Text in Cell
Ryan,
Use two events. See code below, but change the address to the address or name of the cell that you
are using.
HTH,
Bernie
MS Excel MVP
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$B$5" Then MsgBox "You double-clicked B5"
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("$B$5")) Is Nothing Then Exit Sub
MsgBox "You can double-click B5 but you cannot edit it."
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End Sub
"RyanH" wrote in message
...
I have a UserForm that adds and edits data on a worksheet. To load the
UserForm the user Double Clicks a cell that contains a reference number, the
macro searchs for the reference number in another worksheet and loads the
UserForm with the associated data. I have to keep the cell unlocked so the
user can double click it. The problem is that it is possible for the user to
delete the reference number. Is there a way to keep that cell from being
changed and still allow my Double Click Event to work?
|