delete sheets after a certain tab

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
755
Office Version
  1. 365
  2. 2010
hi,

im wondering if there's a way via vba to delete any sheets to the right of the "summary" tab in my workbook.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
How about
Code:
Sub daveyc18()
   Dim i As Long
   
   Application.DisplayAlerts = False
   For i = Sheets("Summary").Index + 1 To Sheets.Count
      Sheets(i).Delete
   Next i
   Application.DisplayAlerts = True
End Sub
 
Upvote 0
You need to delete backwards from the last sheet to the Summary sheet since after you delete a sheet, the Sheets.Count will get throw off and going forward it won't delete that last sheet. Try this:

Code:
Sub dsheet()
Application.DisplayAlerts = False
Dim i As Integer

For i = Sheets.Count To Sheets("Summary").Index + 1 Step -1
    Sheets(i).Delete
Next i
Application.DisplayAlerts = True
End Sub
 
Upvote 0
You need to delete backwards from the last sheet to the Summary sheet since after you delete a sheet, the Sheets.Count will get throw off and going forward it won't delete that last sheet. Try this:

Code:
Sub dsheet()
Application.DisplayAlerts = False
Dim i As Integer

For i = Sheets.Count To Sheets("Summary").Index + 1 Step -1
    Sheets(i).Delete
Next i
Application.DisplayAlerts = True
End Sub

worked like a charm..thanks
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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