View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
SuperJas SuperJas is offline
external usenet poster
 
Posts: 66
Default Error with Target.Name.Name in Worksheet_Change event

Hi!

I wish to prevent users from changing the contents of 2 cells, named "st_xs" and "distrib". My current code is as follows:

-----------------------------------------------------------

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Name.Name = "st_xs" or Target.Name.Name = "distrib" Then

Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True

MsgBox "Sorry, You are not allowed to change this cell!", vbCritical, "Permission Denied!"

End If

End Sub

-----------------------------------------------------------

This code works fine when the user changes those 2 cells, but when another cell is changed, I get an Object/Range Error ('1004')...

I know that using Target.Address instead of Target.Name.Name does the trick, but I'd like to avoid this if possible, since I'd like to let users insert cells/rows etc.

Can someone please help?

Thanks very much in advance!

SuperJas.