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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
Code:
Sub ERed1()
   Dim ws As Worksheet
   Application.DisplayAlerts = False
   For Each ws In Worksheets
      If ws.Name Like "*(*)" Then ws.Delete
   Next ws
   Application.DisplayAlerts = True
End Sub
 
Upvote 0
This code will do that:
Code:
Sub DeleteSheets()
    Dim ws As Worksheet
    Application.DisplayAlerts = False
    For Each ws In Worksheets
        If Left(ws.Name, 7) = "Sheet 1" Then ws.Delete
    Next ws
    Application.DisplayAlerts = True
End Sub
 
Upvote 0
So I implemented this into my code, and I got it to delete "Sheet 1 (2)", but it isn't deleting "Sheet 1". So Here is what my code looks like with yours in it.
Code:
 Application.DisplayAlerts = False
   Sheets(Array("Merged", "Cat", Dog", "Plant", "Lizard", "Frog")). _    Select
    ActiveWindow.SelectedSheets.Delete
    
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.Name Like "*(*)" Then ws.Delete
    Next ws


Application.DisplayAlerts = True
 
Last edited:
Upvote 0
Did you try my code?
I tested it out, and it will delete any Sheet name that starts with "Sheet 1".
 
Last edited:
Upvote 0
Try Joe's code, I misunderstood & thought you only wanted to delete the sheets with (1) etc, rather than all sheets that contained Sheet1 in the name
 
Upvote 0
So I tried both of your code, and Fluff's cleared the ones after, while Joe's cleared the first sheet, so I just put both of those in there and it works great that way.
 
Upvote 0
So I tried both of your code, and Fluff's cleared the ones after, while Joe's cleared the first sheet, so I just put both of those in there and it works great that way.
I created sheets named "Sheet 1", "Sheet 1 (2)", and "Sheet 1 (3)", like shown in your example, and it deleted all of them.
If my original code, as-is, did not do that for you, then I suspect that your sheets are really not named the way you first said in your original post.
 
Upvote 0
In that case use
Code:
If Left(ws.Name, 6) = "Sheet1" Then ws.Delete
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,847
Members
452,361
Latest member
d3ad3y3

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