Avatar of Seamus2626
Seamus2626
Flag for Ireland asked on

Delete all sheets except sheet1 (VBA)

Hi, I need a line of code that deletes all sheets in the current workbook except the sheet called "Sheet1"

Thanks
Visual Basic ClassicMicrosoft ExcelVBA

Avatar of undefined
Last Comment
Seamus2626

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Joe Howard

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ryan Chong

credits to MacroShadow, minor amendment to make it better:

Sub Demo(KeepWsh As String)
    Dim sht As Worksheet
    Application.DisplayAlerts = False
    For Each sht In ActiveWorkbook.Sheets
        If sht.Name <> KeepWsh Then
            sht.Delete
        End If
    Next sht
    Application.DisplayAlerts = True
End Sub

Open in new window

then:
Call Demo("Sheet1")

Open in new window

Seamus2626

ASKER
Thanks!
Seamus2626

ASKER
Thanks for the add Ryan :)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23