Hi
@MKLAQ. There is a problem with your logic there. When a sheet is deleted, the index numbers of the sheets are recalculated for the remaining sheets. So if you were to enter 2,3,4, thinking that you would be deleting the 2nd, 3rd, and 4th sheets, you would actually be deleting the 2nd, 4th, and 6th sheet. You would actually have to enter 2,2,2 to delete the 2nd, 3rd, and 4th sheet. Because of that potential confusion, I came up with some code that will delete the sheets one at a time for you:
VBA Code:
Sub SheetDeleter()
'
' This will delete workbook sheets according to the index number of the sheet entered by the user
'
Dim UserInput As Long
'
UserInput = Application.InputBox("Enter Sheet index to Delete", Type:=1) ' Type:=1 means integer
'
Do Until UserInput = False
If UserInput <> False Then
Application.DisplayAlerts = False ' Turn display alerts off
'
ThisWorkbook.Sheets(UserInput).Delete ' Delete sheet
'
Application.DisplayAlerts = True ' Turn display alerts back on
'
UserInput = Application.InputBox("Enter Sheet index to Delete", Type:=1) ' Type:=1 means integer
End If
Loop
End Sub
If you wanted to start rapidly deleting sheets starting with the 2nd sheet, you could start the script and when the popup box appears, you could just start hitting 2,Enter,2,Enter,2,Enter, etc.
Let us know if that works for you.