H
Han
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?
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?