Delete Tabs

A

Ardy

If I create 5 tabs based on some variables in one other tab, how would
I delete the created tabs.
i.e
I have TAB 1, in this tab I have code (Thanks to this group) I will
create TAB 2, 3, 4, 5. The numbers of tabs are unknown it depends on
the list on tab 1. I need to delete tab 2, 3, 4, 5 but not 1. So the
code I assume needs to make a list of all existing tabs have an
exception not to delete 1 and delete the rest.

Ardy
 
G

Guest

I'm confused on how you will determine which pages to keep. But by your
desciption
tmp = ThisWorkbook.Sheets.Count
this tells you how many sheets there are
Sheets(1).Delete
that will delete a sheet

-John
 
T

Tom Ogilvy

Sub ABCD()
Dim i As Long
Application.DisplayAlerts = False
For i = Sheets.Count To 2 Step -1
Sheets(i).Delete
Next
Application.DisplayAlerts = True

End Sub
 
A

Ardy

Tom
Thank you.......can You educate me on one thing. Not being a
programmer but familiar woth the concepts I fallow all of the logic but
get lost in

For i = Sheets.Count To 2 Step -1

I undrestand the For statement but don't quit get the 2 step -1, can
you shed some light on this......

Regards
Ardy
 
T

Tom Ogilvy

it counts backwards.

--
Regards,
Tom Ogilvy


Ardy said:
Tom
Thank you.......can You educate me on one thing. Not being a
programmer but familiar woth the concepts I fallow all of the logic but
get lost in

For i = Sheets.Count To 2 Step -1

I undrestand the For statement but don't quit get the 2 step -1, can
you shed some light on this......

Regards
Ardy
 
A

Ardy

So Is 2 the first tab or the last tab, or How would one determine that

Thanks.......
 
T

Tom Ogilvy

2 is the second tab from the left - you said you didn't want to do anything
to the first tab, which is 1. So it counts down from the rightmost tab to
the left. (assuming you have a version of excel that works from left to
right).
 

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