Delete some of the sheets

22strider

Active Member
Joined
Jun 11, 2007
Messages
311
Hello Friends

Could you please help me with a code that would read the current spreadsheet names of the workbook and then delete some of those sheets.
For example the current sheet names are:

Input
Budget12
Budget13
Sheet4
Sheet5
Sheet6

The code needs to delete all the sheets other than the following: Input, Budget12, Budget13.

It would be helpful if the code could ignore sheet name that contains text "Budget" rather than ignoring Budget12 and Budget13. That would help making it more dynamic.

Thanks
Rajesh
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
First,Where are the sheets names?i.e A1 to a various row for example.
Second,What about "Input",it shouldn't be deleted although it doesn't have "Budget"? (Should the macro only delete the sheets with names containing "Sheet"?)
ZAX
 
Upvote 0
Try this in a copy of your workbook:
Code:
Sub Test()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Worksheets
    If LCase(ws.Name) <> "input" And Not lower(ws.Name) Like "budget*" Then
        ws.Delete
    End If
Next ws
Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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