Link to home
Start Free TrialLog in
Avatar of Seamus2626
Seamus2626Flag 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
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Seamus2626

ASKER

Thanks!
Thanks for the add Ryan :)