How to have errr msg pop up when user clicks on locked cell

P

perfection

I have locked certain cells of a worksheet and password protected the
sheet. When a user clicks on the cells i have locked i wish that a
mesage pops up telling him thath eis unauthorised to use those cells
or something equivalent - Right now the cursor merely moves back to
last used unlocked cell. can this ne done?

PS By default when i proetect a worksheet all cells are locked and
when i click on a locked cell a warning does pop up informing me to
unprotect worksheet etc but when i lock selected cells this warning
does not pop up and instead behaves as explained above
 
E

excelent

Rightclick on sheet-tab and insert this in program-code window


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox ("This cell is locked")
End Sub


"perfection" skrev:
 
E

excelent

ups-forgot somthing use this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("A1,A5,B7,D11")) Is Nothing Then Exit Sub '
insert ur locked cells here
MsgBox ("This cell is locked")
End Sub


"excelent" skrev:
 
J

JMB

Or perhaps test to see if the cell is locked and worksheet protection is
enabled?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Locked And Target.Parent.ProtectContents Then
MsgBox "Cell is locked"
End If
End Sub
 
M

mikerickson

Have you used the EnableSelection property? It allows you to control the
selection behaviour of a protected worksheet

Code:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top