VBA to delete sheets that don't end in a certain criteria

matratus34

Board Regular
Joined
Nov 21, 2013
Messages
74
Hi all,
Been trying with no luck to write a bit of code to delete all sheet in m workbook that don't end in the word "Trust".
I have a report with 50 tabs with 15 of them named xxxx_Trust.
These 15 are the only ones I need to keep in my final version.
Any help is greatly appreciated.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How about
Code:
Sub delShts()
   Dim ws As Worksheet
   Application.DisplayAlerts = False
   For Each ws In Worksheets
      If Not LCase(ws.name) Like "*trust" Then ws.Delete
   Next ws
   Application.DisplayAlerts = True
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,092
Messages
6,123,064
Members
449,090
Latest member
fragment

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