Easy way to delete Tabs

ERed1

Board Regular
Joined
Jun 26, 2019
Messages
104
Hi all,

I was just wondering if anyone new a macro that deleted specific tabs based on part their name. I have a macro that creates new tabs, but every tab has "Sheet 1" in it, the later tabs have "Sheet 1 (2)", "Sheet 1 (3)", etc. I just need those tabs to be deleted at the push of a button. I can explain more if someone needs it.

thanks in advance for the help
 

ERed1

Board Regular
Joined
Jun 26, 2019
Messages
104
Code:
    Dim ws As Worksheet    For Each ws In Worksheets
        If Left(ws.Name, 7) = "Sheet1" Then ws.Delete
    Next ws


   For Each ws In Worksheets
      If ws.Name Like "*(*)" Then ws.Delete
   Next ws

Here is what it looks like when I used both of yours.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

ERed1

Board Regular
Joined
Jun 26, 2019
Messages
104
I did the change that you just said Fluff, and I got that to work.

Thank you both for the help!
 
Last edited:

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
59,500
Office Version
  1. 365
Platform
  1. Windows
So I just noticed this; they are named "Sheet1". There isn't a space in there.
Yep, just as I suspected. As Fluff posted in post 10, that is a simple change to that one line in my code.
Hopefully you can see that and understand it, so you can figure out these minor adjustments on your own, and can maintain the code going forward.
 

Forum statistics

Threads
1,144,391
Messages
5,724,075
Members
422,535
Latest member
navjeet

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