Why we need macro to do it? It sometimes become cumbersome to find and delete hidden tabs in a worksheet or hidden worksheets in a workbook so we are providing you straight forward method to do so.
Remove hidden worksheets macro : make sure that you have a backup copy of this workbook just in case.
Sub DeleteHiddenWorksheets() i = 1 While i <= Worksheets.Count If Not Worksheets(i).Visible Then Worksheets(i).Delete Else i = i + 1 End If Wend End Sub
Found this one on mrexcel here this macro will delete all sheets except the one you want to keep. Here user wants to prevent “Test O2 and CO2” from being deleted.
Sub test() Dim ws As Worksheet Application.DisplayAlerts = False For Each ws In ThisWorkbook.Worksheets If ws.Visible <> True And ws.Name <> "Test O2 and CO2" Then ws.Delete End If Next ws Application.DisplayAlerts = True End Sub