Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Error on Code

Hi,

I am using the code below to stop the wrong users inserting / deleting rows
or columns.

Problem is it works once, but if it is tried twice it fails at the .Undo
point in the code.

Any Ideas?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim Msg As String
Dim pWord As String
pWord = "mypassword"
Msg = "Deleting or Inserting Rows/Columns Not Permitted - Contact Workbook
Author for access"
If Target.Address = Target.EntireRow.Address Or _
Target.Address = Target.EntireColumn.Address Then
response = InputBox("Enter password")
If response = pWord Then Exit Sub
With Application
..EnableEvents = False
..Undo
Msg = MsgBox(Msg, 16, "WARNING - PERMISSION REFUSED")
..EnableEvents = True
End With
Else
Exit Sub
End If
End Sub

Craig
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Error on Code

Worked just fine for me when I started with a new workbook and pasted the
code in. I could try to delete rows and columns at will and your code worked
just fine.

What is the error message you're getting? Is there other code in your
workbook? Are any of the worksheets or the workbook protected?

Eric

P.S. - if you put Option Explicit at the top of the module, you'll be
chastized for not declaring "response"!


"Craig" wrote:

Hi,

I am using the code below to stop the wrong users inserting / deleting rows
or columns.

Problem is it works once, but if it is tried twice it fails at the .Undo
point in the code.

Any Ideas?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim Msg As String
Dim pWord As String
pWord = "mypassword"
Msg = "Deleting or Inserting Rows/Columns Not Permitted - Contact Workbook
Author for access"
If Target.Address = Target.EntireRow.Address Or _
Target.Address = Target.EntireColumn.Address Then
response = InputBox("Enter password")
If response = pWord Then Exit Sub
With Application
.EnableEvents = False
.Undo
Msg = MsgBox(Msg, 16, "WARNING - PERMISSION REFUSED")
.EnableEvents = True
End With
Else
Exit Sub
End If
End Sub

Craig

Reply
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
(Error 1004) Object Defined Error ...simple code Robert Crandal Excel Programming 1 January 12th 10 10:31 PM
Problem with code (error code 9) Vince Excel Programming 3 October 12th 09 04:16 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Error in Excel VBA Code (Error 91) dailem Excel Programming 1 August 25th 06 03:45 PM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


All times are GMT +1. The time now is 10:38 PM.

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

About Us

"It's about Microsoft Excel"