Option Explicit
Private Sub CommandButton1_Click()
Dim MyArray() As Variant
Dim i As Long
Dim Cnt As Long
With Me.ListBox1
Cnt = 0
For i = 0 To .ListCount - 1
If .Selected(i) Then
Cnt = Cnt + 1
ReDim Preserve MyArray(1 To Cnt)
MyArray(Cnt) = .List(i)
End If
Next i
If Cnt > 0 Then
If Worksheets.Count > UBound(MyArray) Then
Application.DisplayAlerts = False
Worksheets(MyArray).Delete
Application.DisplayAlerts = True
Call UpdateSheetList
Else
MsgBox "A workbook must contain at least one visible sheet.", vbExclamation
End If
Else
MsgBox "Please select one or more sheets for deletion...", vbExclamation
End If
End With
End Sub
Private Sub UserForm_Initialize()
Call UpdateSheetList
End Sub
Private Sub UpdateSheetList()
Dim wks As Worksheet
With Me.ListBox1
.Clear
For Each wks In Worksheets
.AddItem wks.Name
Next wks
End With
End Sub