Thread: Delete Sheets
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Delete Sheets

Sticking with the Selected Sheets idea of the other two posters, you can do
it with this simpler macro...

Sub DeleteSelectedSheets()
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
End Sub

Be careful with it, though... it will delete the active sheet if you run it
by mistake and having the DisplayAlerts set to False means it will not warn
you first.

--
Rick (MVP - Excel)


"Bre-x" wrote in message
...
I have this vba code that allows me to delete all the sheets but the one is
active.

Is there a way to delete all sheets but the ones "selected"??

workbook has 4 sheets: 1,2,3,4
If I select 2 and 3, delete 1 and 4

----------------------------------------
'Delete all but active sheet
For Each sheete In Sheets
If ActiveSheet.Index < sheete.Index Then
Application.DisplayAlerts = False
sheete.Delete
Application.DisplayAlerts = True
End If
Next sheete