if sheets name contrains phrase "example" delete this sheet

pudle

New Member
Joined
Jul 19, 2012
Messages
8
im trying to write a macro to tidy up a workbook with allot of unnecessary sheets, what id like to do is delete all sheets the contain the word/phrase " v " (note spaces either side of the v). Browsing around i found this macro bellow, but it dose the opposite, it keeps all the sheets with " v " and deletes all the others, i just cant figure out how to get it to work the other way

Sorry if this is such an easy question, im pretty new to vba !

Code:
Sub DeleteWS()
For Each ws In Sheets
Application.DisplayAlerts = False
If ws.Name <> " v " Then ws.Delete
Next
Application.DisplayAlerts = True
End Sub
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,693
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Rich (BB code):
Sub DeleteWS()
For Each ws In Sheets
Application.DisplayAlerts = False
If ws.Name = " v " Then ws.Delete
Next
Application.DisplayAlerts = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,207
Messages
5,594,841
Members
413,944
Latest member
3xc3ln00b

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
Top