Peter,
Please test this first on a test workbook or two. This will keep the sheets
you select in the userform and delete the rest. Note that you can select
groups of sheets in the userform by using the Control or Shift keys.
Create a UserForm1 with a ListBox1 and a CommandButton1 and put the code
below inside the UserForm1:
Private Sub UserForm_Initialize()
Dim sh As Worksheet
Me.ListBox1.MultiSelect = fmMultiSelectExtended
For Each sh In ActiveWorkbook.Worksheets
Me.ListBox1.AddItem (sh.Name)
Next sh
End Sub
Private Sub CommandButton1_Click()
Dim sheets_selected, delete_sheets As Boolean
Dim i As Integer
sheets_selected = False
delete_sheets = False
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
sheets_selected = True
Exit For
End If
Next i
End With
If sheets_selected Then
delete_sheets = MsgBox(prompt:="Selected Sheets Will Be Kept" & vbCrLf &
_
"Those NOT Selected Will be DELETED", _
Buttons:=vbOKCancel + vbExclamation, _
Title:="Delete UnSelected Sheets") - 2
If delete_sheets Then
With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = False Then
Application.DisplayAlerts = False
ActiveWorkbook.Worksheets(.List(i)).Delete
Application.DisplayAlerts = True
End If
Next i
End With
End If
End If
Unload Me
End Sub
Call the form in a regular module with:
UserForm1.Show
hth,
Doug