Delete worksheets based on a list

aerobharath15

New Member
Joined
Mar 14, 2018
Messages
11
hi All,

With the help of a member here, i managed to create multiple WORKSHEETS based on a list using the code below. but now i want a macro to delete all the created worksheets without deletion prompt window. Please someone can help urgently.

Sub makeSheets()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("Template")
Set sh2 = Sheets("Points")
For Each c In sh2.Range("B5", sh2.Cells(Rows.Count, 2).End(xlUp))
sh1.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value: ActiveSheet.Range("D5") = c.Value
Next
End Sub
 
If it is all being done automatically by a macro, what difference does it really make?

Are there any other sheets other than "Points" and "Template" that you want to keep?
If not, you can just delete all sheets not named those, and there is no need to loop through a list somewhere on your sheet.

Hi Joe, thats a good point. We can delete all sheets except the 2 sheets above.

Also, please can you provide the fix i requested? Your code is deleting the sheets from the list from third row. first and second row from the list is not touched at all. thanks.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi Joe, thats a good point. We can delete all sheets except the 2 sheets above.
Then try this code. You don't need to worry about the list in this case.
Code:
Sub DelSheets()

    Dim ws As Worksheet
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    For Each ws In Worksheets
        If ws.Name <> "Points" And ws.Name <> "Template" Then ws.Delete
    Next ws
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
Then try this code. You don't need to worry about the list in this case.
Code:
Sub DelSheets()

    Dim ws As Worksheet
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    For Each ws In Worksheets
        If ws.Name <> "Points" And ws.Name <> "Template" Then ws.Delete
    Next ws
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
End Sub

Works perffectly.. thanks a lot :)
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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