macro to delete all sheets after a specific one

Phil1981

New Member
Joined
May 27, 2011
Messages
27
I have a workbook that contains 11 sheets with names that never change. What I would like to have is a macro that will delete all other sheets but keep my original 11 sheets.

All the original sheets are Sheet1, Sheet2 ... Sheet11 etc.

Any help would be appreciated.

Sorry I should specify that new sheets are created between Sheet10 and Sheet11

so
Sheet1 | Sheet2 | Sheet3 |...Sheet10 | newSheet1 | newSheet2 | Sheet11
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try

Code:
Sub DelSheets()
Dim ws As Worksheets
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
    With ws
        If IsError(Application.Match(ws.Name, Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6", "Sheet7", "Sheet8", "Sheet9", "Sheet10", "Sheet11"), 0)) Then ws.Delete
    End With
Next ws
Application.DisplayAlerts = True
End Sub
 
Upvote 0
Code:
Sub DelExtraShts()
Dim r As Integer
Dim sheetc As Integer


Application.DisplayAlerts = False
Application.ScreenUpdating = False

Sheets("Sheet11").Move After:=Sheets(10)
sheetc = Sheets.Count

For r = sheetc To 12 Step -1
Worksheets(r).Delete

Next r


Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
 
Last edited:
Upvote 0
try this

Code:
Sub DeleteWS()
'
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Sheets
Select Case sh.Name
Case "Sheet1", "Sheet2", "Sheet3", "Sheet4" 'etc add each one you want to keep
'Do nothing
Case Else
sh.Delete
End Select
Next sh
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,240
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top