VBA Code Required for deleting All Sheets except Sheet1

  • Thread starter Thread starter Ms-Exl-Learner
  • Start date Start date
M

Ms-Exl-Learner

Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.
 
Sub delsheets()
Dim sh as Sheet

For Each sh in ActiveWorkbook.Sheets
If sh.Name<>"Sheet1" Then
sh.Delete
End If
Next sh

End Sub
 
Sub SheetRemover()
k = Sheets.Count
For i = k To 2 Step -1
Sheets(i).Delete
Next
End Sub
 
Thank you it’s working fine but if I run the Macro then its asking me to
Confirm Do you want to delete this sheet like that for each and every
worksheet before deleting. I am having 200 sheets for 200 times I need to
click or Press enter for deleting the sheets.

Please help me…
 
Not for 200 times 199 times. Please set the macro without any message box
confirmation.
 
Sub SheetRemover()
k = Sheets.Count
Application.DisplayAlerts = False
For i = k To 2 Step -1
Sheets(i).Delete
Next
Application.DisplayAlerts = True
End Sub
 
forgot to include the

Application.DisplayAlerts = False
....
Application.DisplayAlerts = True

part
 
Back
Top