VBA Code to Delete All Sheets/Tabs between two Specific Tabs/Sheets

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
439
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for any suggestions which I will provide feedback.

Why does nothing happens when I run the following code as I'm trying delete all the sheets between the "Start" and "End" sheets?

Code:
Sub DltShts()


    'Dimensioning
        Dim i As Long


    'Turn off Screen Update
        Application.ScreenUpdating = False


    'Turn off Automatic Calculation
        Application.Calculation = xlManual


    'Delete sheets between "START" and "END"
        With ActiveWorkbook


            For i = .Worksheets("START").Index To .Worksheets("END").Index Step -1


                .Worksheets(i).Delete
        
            Next i
        
        End With


    'Turn on Screen Update
        Application.DisplayAlerts = True




End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Maybe try this way

Code:
Sub MM1()
  Dim X As Long
  Application.DisplayAlerts = False
  For X = Sheets("END").Index - 1 To Sheets("START").Index + 1 Step -1
    Sheets(X).Delete
  Next
  Application.DisplayAlerts = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,532
Messages
6,172,875
Members
452,486
Latest member
standw01

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