how to delete unwanted sheets

  • Thread starter Thread starter N E Body
  • Start date Start date
N

N E Body

Hello everyone

I want to clear a workbook of all but 3 worksheets on opening th
workbook.
Unfortunately I do not know the names of the sheets to delete -
simply want to keep "Log", "Data", Lists" - There may be as many as 1
unwanted sheets.

Could anyone suggest code to do this?

TIA

Kenny
Various combinations of
Win Me, 2000,XP
Office 97 and 200
 
Sub SheetDelete()

For Each sht In Worksheets

If sht.Name <> "Log" And sht.Name <> "Data" And sht.Name <> "Lists
Then
sht.Delete
End If

Next

End Sub


but the problem is this will prompt you whether to delete or not. Ther
is a way around this which I am not remembering at the moment

- Manges
 
ok. here it is. Use

Sub DeleteSheet()

Application.DisplayAlerts = False

For Each sht In Worksheets
If sht.Name <> "Log" And sht.Name <> "Data" And sht.Name <
"Lists" Then
sht.Delete
End If

Next

Application.DisplayAlerts = True
End Su
 

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