Thread: Delete sheets
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
keiji kounoike keiji kounoike is offline
external usenet poster
 
Posts: 199
Default Delete sheets

I think it is rather difficult to input sheet's name correctly. if the
number of the sheets you want to leave is a few compared to the sheets
you want to delete, first select all the sheets you want to leave, then
run the macro below.

Sub Delunselectedsheets()
Dim v As Sheets, sh As Worksheet
Dim arr()
Dim i As Long

Set v = ActiveWindow.SelectedSheets
ReDim arr(v.Count - 1)
For Each sh In v
arr(i) = sh.Name
i = i + 1
Next

Application.DisplayAlerts = False
For Each sh In Worksheets
If IsError(Application.Match(sh.Name, arr, 0)) Then
sh.Delete
End If
Next
End Sub

Keiji

Sverre wrote:
I have a workbook with many diefferent sheets. I need a makro to delete all
sheets except 4 sheets named:
Elevdata,
Rapportvalidering,
Kontrollark,
Samleark,

It is not possible to record a makro because the sheets can appear with
different names.

Regards Sverre