Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Deleting Specific Sheets in Workbook

Question posted by: deve8ore (Newbie) on July 23rd, 2008 05:38 PM
Hello,

I have an Excel workbook that has a number of sheets, where "Graphs" begin at Sheet16 and can either be a couple sheets, or many (i.e. 20).

Could someone assist on how I can code to select sheet16 through the end of the workbook, and then simply delete the sheets?

So far I've tried the following with no success (it eliminates some sheets, not all). Thanks in advance for your help!!!

----------------------------------------------

Dim iSheetCount As Integer
Dim iSheet As Integer
Dim ws As Integer

Application.DisplayAlerts = False

On Error Resume Next
iSheetCount = ActiveWorkbook.Worksheets.count
For iSheet = 16 To iSheetCount
Worksheets(iSheet).Delete
Next iSheet

Application.DisplayAlerts = True
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
anuragshrivastava64's Avatar
anuragshrivastava64
Member
61 Posts
July 24th, 2008
10:52 AM
#2

Re: Deleting Specific Sheets in Workbook
may be changing the for loop works
Try this

For iSheet = iSheetCount To 16 Step -1
Worksheets(iSheet).Delete
Next iSheet

Reply
MikeTheBike's Avatar
MikeTheBike
Expert
261 Posts
July 24th, 2008
12:14 PM
#3

Re: Deleting Specific Sheets in Workbook
Quote:
Originally Posted by deve8ore
Hello,

I have an Excel workbook that has a number of sheets, where "Graphs" begin at Sheet16 and can either be a couple sheets, or many (i.e. 20).

Could someone assist on how I can code to select sheet16 through the end of the workbook, and then simply delete the sheets?

So far I've tried the following with no success (it eliminates some sheets, not all). Thanks in advance for your help!!!

----------------------------------------------

Dim iSheetCount As Integer
Dim iSheet As Integer
Dim ws As Integer

Application.DisplayAlerts = False

On Error Resume Next
iSheetCount = ActiveWorkbook.Worksheets.count
For iSheet = 16 To iSheetCount
Worksheets(iSheet).Delete
Next iSheet

Application.DisplayAlerts = True

Hi

I think more info is require.

Do we assume that all sheets to be deleted have 'Graphs' (Charts) in them??

You do not say which sheets are not deleted, that should be, or give any clue as to why not (are they perhaps charts and not sheets?).


MTB

Reply
deve8ore's Avatar
deve8ore
Newbie
27 Posts
July 24th, 2008
12:34 PM
#4

Re: Deleting Specific Sheets in Workbook
Hello,

Thanks for the feedback.

I've made the Excel tool so the additional sheets will always be starting at "Sheet16", and then go towards the end of the workbook.
The names of the sheets are always changing, therefore I'd prefer to have the code to delete "Sheet16" through the end of the workbook, whether it be "Sheet20", or "Sheet57".

Not all of the Sheets have graphs.... some only data.... I simply want to delete those sheets with a macro.... with the press of a button.

Thanks again for your help!

Reply
MikeTheBike's Avatar
MikeTheBike
Expert
261 Posts
July 25th, 2008
08:11 AM
#5

Re: Deleting Specific Sheets in Workbook
Quote:
Originally Posted by deve8ore
Hello,

Thanks for the feedback.

I've made the Excel tool so the additional sheets will always be starting at "Sheet16", and then go towards the end of the workbook.
The names of the sheets are always changing, therefore I'd prefer to have the code to delete "Sheet16" through the end of the workbook, whether it be "Sheet20", or "Sheet57".

Not all of the Sheets have graphs.... some only data.... I simply want to delete those sheets with a macro.... with the press of a button.

Thanks again for your help!

Just to confirm, you want to delete all SHEETS after sheet 15 that have an EMBEDDED chart and leave all sheets that contain data only ??

If this is the case, and you do not know what the sheet name(s) are, then this becomes tricky because you cannot define "Sheet15" or later.



MTB

Reply
deve8ore's Avatar
deve8ore
Newbie
27 Posts
July 27th, 2008
03:28 AM
#6

Re: Deleting Specific Sheets in Workbook
Actually it won't matter what's in the sheets... chart, no chart, just data, embedded picture... I just want anything greater than sheet #15 deleted.

I'd also like to know how to delete named sheets from sheet named "Total" to a sheet named "Data", and everything in between. This may sound odd, but we get data from an outside vendor that can have many sheets, but their first sheet is always named "Total", and last sheet is named "Data". I want to delete both the "Total" & "Data" sheets, and every and any sheets in between.

Thanks again for asking questions to clarify what I'm looking for!

Reply
Reply
Not the answer you were looking for? Post your question . . .
184,012 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Visual Basic Forum Contributors