delete multiple worksheets from within workbook

jammoca

Banned
Joined
Nov 6, 2002
Messages
1,100
I have a workbook that has about 400 worksheets named Sheet 1 through to Sheet 400.

On another sheet called 'Index' within the same workbook, I have a list (in cells C10:C40) that will have only some of the names of the sheets within that same workbook eg:

Sheet 13
Sheet 86
Sheet 112
Sheet 144
Sheet 189
Sheet 232
Sheet 279
Sheet 318

I'd like a button on that 'Index' sheet that, when pressed, will delete from the workbook, any sheet NOT included in the C10:C40 list.

Is this possible, and if so, what code would be needed ?

All the best,

Chris
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Maybe like this, but untested:
Code:
Sub x()
    Dim wks         As Worksheet
    Dim r           As Range
 
    With ThisWorkbook
        Set r = .Worksheets("Index").Range("C10:C40")
        On Error Resume Next
        Application.DisplayAlerts = False
 
        For Each wks In .Worksheets
            If IsError(Application.Match(wks.Name, r, 0)) Then wks.Delete
        Next wks
    End With
 
    Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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