• Deleting Sheets via macro (2003)

    Author
    Topic
    #433845

    Hello,

    This is an easy question. Is there a way to create a macro to delete all the sheets in an Excel file except for one sheet call “recap”. The name of the file is also call “recap” in case you need to know.

    Viewing 1 reply thread
    Author
    Replies
    • #1021471

      Assuming it is the active workbook:

      Sub DeleteAllButOne()
      Dim i As Integer
      Application.DisplayAlerts = False
      With ActiveWorkbook
      For i = .Sheets.Count To 1 Step -1
      If Not .Sheets(i).Name = “recap” Then
      .Sheets(i).Delete
      End If
      Next i
      End With
      Application.DisplayAlerts = True
      End Sub

      If it isn’t necessarily the active workbook, replace ActiveWorkbook with Workbooks(“recap.xls”)

    • #1021472

      Thanks Hans.

    Viewing 1 reply thread
    Reply To: Deleting Sheets via macro (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: