LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
REPSOT?? Sub Worksheet_Change(ByVal Target As Range) Ed Davis[_2_] Excel Discussion (Misc queries) 14 October 13th 09 03:20 PM
Worksheet_change event handler error gen Excel Discussion (Misc queries) 0 January 18th 08 04:55 AM
Multiple values in Private Sub Worksheet_Change(ByVal Target As R davemon Excel Discussion (Misc queries) 2 September 21st 07 07:40 PM
Control Toolbox and Private Sub Worksheet_Change(ByVal Target As R Toppers Excel Discussion (Misc queries) 0 August 17th 07 02:02 AM
Many Sub Worksheet_Change(ByVal Target As Range) In One Worksheet MathewPBennett Excel Programming 4 December 24th 03 01:01 PM


All times are GMT +1. The time now is 04:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"