Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Disable row delete in a worksheet (not all worksheets in theworkbook)

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Disable row delete in a worksheet (not all worksheets in the workb

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Disable row delete in a worksheet (not all worksheets in theworkb

Superb! Thanks John.

On 8 Oct, 16:08, john 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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Disable row delete in a worksheet (not all worksheets in the w

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 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
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
Countif and Sumif with refrence value a Cell on another Sheet in theWorkbook Mike 215 Excel Discussion (Misc queries) 3 September 3rd 09 03:51 AM
Disable Worksheet Delete Warning Charles in Iraq Excel Programming 1 March 30th 07 08:51 AM
VBA to disable "Delete...." on shortcut menu of worksheet tab? Mary Kathryn Excel Discussion (Misc queries) 3 March 3rd 06 05:54 PM
Disable Worksheet Delete Dialog Greg Excel Programming 1 March 1st 05 08:32 PM
Disable Add/Delete/Move Worksheets jamiee Excel Programming 1 January 5th 04 06:50 PM


All times are GMT +1. The time now is 10:13 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"