Delete all but 1 sheet in workbook

  • Thread starter Thread starter cdclayton
  • Start date Start date
C

cdclayton

A2K

Using code, how do I loop through all the worksheets in a workbook and
delete all but the first one, "Sheet1"

Thanks,

Charles D Clayton Jr
 
try
Sub deleteallsheets()
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name <> "Sheet1" Then ws.Delete
Next
Application.DisplayAlerts = True
End Sub
 
Thanks for your help. One more question, is it possible to have this
work no matter what the sheet is renamed to?

Thanks,

Charles D Clayton Jr
 
try
Sub deleteallsheets()
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Index <> 1 Then ws.Delete
Next
Application.DisplayAlerts = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top