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: 6
Default Event: Workbook_SheetDelete

Abbreviated Question #1:
Is there an event such as "Workbook_SheetDelete" in existence that I
could use? I found a "Workbook_SheetNew," so I figured there would be
a counterpart. I need my code to execute whenever a worksheet is
deleted.

Abbreviated Question #2:
Where do I put the event code? In "ThisWorkbook" under "Microsoft
Excel Objects" or somewhere else?

---------------------------------------------------------------------
Extended Explanation for Question #1 and #2:
(You only need to read the text below if it will help you answer my
questions)

My workbook has a sheet that is "VeryHidden." For the sake of
avoiding confusion, I shall call this sheet by its CodeName: Sheet1.
Sheet1 keeps track of sheets I create after Sheet6 and looks something
like this:

No. Name CodeName
1 Cap Sheet7
2 Bottle Sheet8
3 Label Sheet9

Another sheet is dependent on Sheet1 and due to the way I have written
the code it is imperative that there are no empty cells in between rows
like this:

No. Name CodeName
1 Cap Sheet7

3 Label Sheet9

The user has the option of deleting a sheet. Say, they delete Sheet8
(No. 2, Bottle). I would like, upon the act of deletion, for this
sheet to update itself to look like this:

No. Name CodeName
1 Cap Sheet7
2 Label Sheet9

I don't care to change the CodeName, but changing the number ("No.")
would be nice.

The code I am planning on using (referenced from another post in Google
Groups) to delete the empty row is:

Private Sub Worksheet_Delete()

Sheet1.Select
activesheet.Columns("A").SpecialCells _
(xlCellTypeBlanks).EntireRow.Delete

End Sub

It works perfectly because Column A will always contain the header,
"No." Part of my code elsewhere temporarily makes Sheet1
"Visible" to run my macros, so Sheet1 being "VeryHidden" should
also not be an issue.

Question #1:
What I am looking for is a way to activate "Worksheet_Delete" whenever
a worksheet is deleted, but I am not aware of a any such Worksheet or
Workbook event. The closest thing I found was
"Workbook_SheetDeactivate." There is also an event called
"Workbook_SheetNew," therefore I figured there would be a counterpart;
perhaps something like "Workbook_SheetDelete." To the best of my
knowledge, the code contained between:

Private Sub Workbook_SheetDeactivate()
...
End Sub

will run whenever a worksheet is deactivated. Correct me if I am
mistaken.

I realize this could all be simplified by adding a button, but I do not
want to burden the user with more buttons. Any suggestions would be
greatly appreciated.

Question #2:
Also, I am not extremely proficient with VB, so I am unsure of where to
place the code for an event such as "Workbook_SheetDeactivate." Should
it be place in "ThisWorkbook" under "Microsoft Excel Objects" or
somewhere else?

 
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
MsgBox in Enter event causes combobox not to run Change event Richard Excel Programming 0 March 6th 06 02:52 PM
How to trap delete row event and hide column event? Alan Excel Programming 3 April 26th 05 04:25 PM
user form-on open event? keydown event? FSt1[_3_] Excel Programming 2 August 5th 04 02:26 PM
Event Procedures: Event on Worksheet to fire Event on another Worksheet Kathryn Excel Programming 2 April 7th 04 07:35 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


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