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
 
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.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I did the change that you just said Fluff, and I got that to work.

Thank you both for the help!
 
Last edited:
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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