Deleting tabs in Excel

S

shoey812

Hi -

I have an Excel workbook with several tabs titled with #'s (Ex: 100,
205, 303, 544, etc.) Is it possible to create a macro that will delete
all the tabs except for a certain group? For example, I would want to
keep tab 205 and 303 but delete all the other ones.

Thanks
Stephen
 
D

Don Guillett

for each ws in worksheets
if ws.name<>"nameone" and ws.name<>"name2" then ws.delete
next
 
D

Dave Peterson

You may want to look at the "select case" example in VBA's Help:

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
Select Case LCase(wks.Name)
Case Is = "205", "303", "keepthis"
'do nothing
Case Else
Application.DisplayAlerts = False
wks.Delete
Application.DisplayAlerts = True
End Select
Next wks

You always have to have at least one visible sheet in the workbook--this code
didn't do any checking for that.
 

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

Top