PC Review


Reply
Thread Tools Rate Thread

Disable row delete in a worksheet (not all worksheets in theworkbook)

 
 
Lucas Reece
Guest
Posts: n/a
 
      8th Oct 2009
Is it possible to prevent deleting of rows in a worksheet within a
workbook? e.g. I have Sheet1, Sheet2, Sheet3 and Sheet4 in the
workbook but only want to prevent deletion of rows in Sheet2.

Can someone offer a solution to this using VBA?

Many thanks.
 
Reply With Quote
 
 
 
 
john
Guest
Posts: n/a
 
      8th Oct 2009
Excel does not provide direct functionality that enables
you to "trap" a row that has been deleted.
This code is stored in the Thisworkbook code module
and should prevent rows from being deleted in a sheet named sheet2.

And of course, it only works if user enables macros.

Hope helpful

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

If Sh.Name = "Sheet2" Then

If Target.Address = Target.EntireRow.Address Then

With Application

.EnableEvents = False

.Undo

msg = MsgBox("Deleting Rows Not Permitted", 16, "WARNING")

.EnableEvents = True

End With

Else

Exit Sub

End If
End If

End Sub
--
jb


"Lucas Reece" wrote:

> Is it possible to prevent deleting of rows in a worksheet within a
> workbook? e.g. I have Sheet1, Sheet2, Sheet3 and Sheet4 in the
> workbook but only want to prevent deletion of rows in Sheet2.
>
> Can someone offer a solution to this using VBA?
>
> Many thanks.
>

 
Reply With Quote
 
Lucas Reece
Guest
Posts: n/a
 
      8th Oct 2009
Superb! Thanks John.

On 8 Oct, 16:08, john <j...@discussions.microsoft.com> wrote:
> Excel does not provide direct functionality that enables
> you to "trap" a row that has been deleted.
> This code is stored in the Thisworkbook code module
> and should prevent rows from being deleted in a sheet named sheet2.
>
> And of course, it only works if user enables macros.
>
> Hope helpful
>
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
>
> * * If Sh.Name = "Sheet2" Then
>
> * * * * If Target.Address = Target.EntireRow.Address Then
>
> * * * * * * With Application
>
> * * * * * * * * .EnableEvents = False
>
> * * * * * * * * .Undo
>
> * * * * * * * * msg = MsgBox("Deleting Rows Not Permitted", 16, "WARNING")
>
> * * * * * * * * .EnableEvents = True
>
> * * * * * * End With
>
> * * * * Else
>
> * * * * * * Exit Sub
>
> * * * * End If
> * * End If
>
> End Sub
> --
> jb
>
> "Lucas Reece" wrote:
> > Is it possible to prevent deleting of rows in a worksheet within a
> > workbook? e.g. I have Sheet1, Sheet2, Sheet3 and Sheet4 in the
> > workbook but only want to prevent deletion of rows in Sheet2.

>
> > Can someone offer a solution to this using VBA?

>
> > Many thanks.


 
Reply With Quote
 
JENC
Guest
Posts: n/a
 
      20th Nov 2009
Is it possible to limit this to one particular row on a worksheet?

John

"Lucas Reece" wrote:

> Superb! Thanks John.
>
> On 8 Oct, 16:08, john <j...@discussions.microsoft.com> wrote:
> > Excel does not provide direct functionality that enables
> > you to "trap" a row that has been deleted.
> > This code is stored in the Thisworkbook code module
> > and should prevent rows from being deleted in a sheet named sheet2.
> >
> > And of course, it only works if user enables macros.
> >
> > Hope helpful
> >
> > Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> >
> > If Sh.Name = "Sheet2" Then
> >
> > If Target.Address = Target.EntireRow.Address Then
> >
> > With Application
> >
> > .EnableEvents = False
> >
> > .Undo
> >
> > msg = MsgBox("Deleting Rows Not Permitted", 16, "WARNING")
> >
> > .EnableEvents = True
> >
> > End With
> >
> > Else
> >
> > Exit Sub
> >
> > End If
> > End If
> >
> > End Sub
> > --
> > jb
> >
> > "Lucas Reece" wrote:
> > > Is it possible to prevent deleting of rows in a worksheet within a
> > > workbook? e.g. I have Sheet1, Sheet2, Sheet3 and Sheet4 in the
> > > workbook but only want to prevent deletion of rows in Sheet2.

> >
> > > Can someone offer a solution to this using VBA?

> >
> > > Many thanks.

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Worksheet Delete Warning =?Utf-8?B?Q2hhcmxlcyBpbiBJcmFx?= Microsoft Excel Programming 1 30th Mar 2007 08:51 AM
Disable Worksheet Delete Dialog =?Utf-8?B?R3JlZw==?= Microsoft Excel Programming 1 1st Mar 2005 08:32 PM
How do I disable the warning message when I delete worksheets in E Frank Stone Microsoft Excel Misc 0 16th Aug 2004 08:43 PM
Re: How do I disable the warning message when I delete worksheets in E Andy Wiggins Microsoft Excel Misc 0 16th Aug 2004 08:34 PM
Disable Add/Delete/Move Worksheets jamiee Microsoft Excel Programming 1 5th Jan 2004 06:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:14 PM.