Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 333
Default Activate code when sheet is deleted

Hi,

Is there a way to run code when a worksheet is deleted?

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Activate code when sheet is deleted

Karen,

Unfortunately there's no worksheet_delete event but there is a workaround.
Alt+f11 - double click This Workbook and paste this in:-

Private sheetname As String
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim sheet As Worksheet
For Each sheet In Worksheets
If sheet.Name = sheetname Then
ok = True
Exit For
End If
Next
If Not ok Then
MsgBox sheetname & " has been deleted" 'Your code goes here
End If
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
sheetname = Sh.Name
End Sub

Mike

"Karen53" wrote:

Hi,

Is there a way to run code when a worksheet is deleted?

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
Run Code On Activate Theresa Excel Worksheet Functions 5 December 18th 07 05:47 AM
Prevent code in "Sheet Activate" from running when sheet made visible from other macr Simon Lloyd[_794_] Excel Programming 10 June 21st 06 09:15 AM
Activate code in cell Steve Excel Programming 5 August 18th 05 07:44 PM
How to activate "New" tab in Dataform through VB Code shajueasow Excel Discussion (Misc queries) 2 May 1st 05 01:15 PM
Return to Current Sheet in On (sheet activate) event macro Paul Moles Excel Programming 1 March 27th 05 03:16 PM


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