Deleting Specific Sheets in Workbook

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deve8ore
    New Member
    • Apr 2008
    • 34

    Deleting Specific Sheets in Workbook

    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.Dis playAlerts = False

    On Error Resume Next
    iSheetCount = ActiveWorkbook. Worksheets.coun t
    For iSheet = 16 To iSheetCount
    Worksheets(iShe et).Delete
    Next iSheet

    Application.Dis playAlerts = True
  • anuragshrivastava64
    New Member
    • Jan 2007
    • 66

    #2
    change order of loop

    may be changing the for loop works
    Try this

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

    Comment

    • MikeTheBike
      Recognized Expert Contributor
      • Jun 2007
      • 640

      #3
      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.Dis playAlerts = False

      On Error Resume Next
      iSheetCount = ActiveWorkbook. Worksheets.coun t
      For iSheet = 16 To iSheetCount
      Worksheets(iShe et).Delete
      Next iSheet

      Application.Dis playAlerts = 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

      Comment

      • deve8ore
        New Member
        • Apr 2008
        • 34

        #4
        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!

        Comment

        • MikeTheBike
          Recognized Expert Contributor
          • Jun 2007
          • 640

          #5
          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

          Comment

          • deve8ore
            New Member
            • Apr 2008
            • 34

            #6
            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!

            Comment

            Working...