Results 1 to 13 of 13

Thread: Reset Excel sheet count?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Is this what you want?


     Public Sub DeleteSheets()
        Dim currentSheet As String
        Dim varAnswer As String
        Dim wsSheet As Worksheet
        Dim strName As String
        currentSheet = ActiveSheet.Name
        varAnswer = MsgBox("This will delete all sheets except for the sheet named '" + _
        currentSheet + "'" + (Chr(13)) + (Chr(13)) + "Click Yes to irreversibly erase " & _
        "the other sheets, or No to cancel this procedure", vbYesNo, _
        "Warning - This Procedure Can Not Be Undone!")
        If varAnswer = vbNo Then
            Exit Sub
        Else:
            Application.DisplayAlerts = False
            With ActiveSheet
                For Each wsSheet In Worksheets
                    strName = wsSheet.Name
                    If strName <> currentSheet Then
                        wsSheet.Delete
                    End If
                Next wsSheet
            End With
        End If
        ActiveSheet.Name = "Sheet1"
        Application.DisplayAlerts = True
    End Sub
    Last edited by Aussiebear; 06-23-2025 at 01:24 PM.
    Peace of mind is found in some of the strangest places.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •