Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Oct 2005
    Location
    Cambridgeshire, USA
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deleting Sheets via macro (2003)

    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deleting Sheets via macro (2003)

    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")

  3. #3
    2 Star Lounger
    Join Date
    Oct 2005
    Location
    Cambridgeshire, USA
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deleting Sheets via macro (2003)

    Thanks Hans.

Posting Permissions

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