+ Reply to Thread
Results 1 to 3 of 3

Loop to Delete worksheets stops after deleting one sheet...

Hybrid View

booDaddy Loop to Delete worksheets... 03-17-2014, 04:54 PM
Sniper Re: Loop to Delete worksheets... 03-17-2014, 05:00 PM
Izandol Re: Loop to Delete worksheets... 03-17-2014, 05:12 PM
  1. #1
    Registered User
    Join Date
    03-17-2014
    Location
    SF Bay
    MS-Off Ver
    Excel 2011 for Mac
    Posts
    1

    Loop to Delete worksheets stops after deleting one sheet...

    Sub DeleteSheetsPlease()

    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    Application.StatusBar = "checking " & ws.Name
    If ws.Name <> "Parameters" And ws.Name <> "About" Then
    Application.DisplayAlerts = False
    Application.StatusBar = "deleting " & ws.Name
    ws.Delete
    Application.DisplayAlerts = True
    End If
    Next ws

    End Sub



    This skips "Parameters" and "About", then it deletes a single sheet (that does not match "Parameters" or "About"),

    BUT THEN IT STOPS, leaving "deleting [WSNAME]" in the appstatus. It's like it skips the "Next ws" statement altogether after deleting a sheet.

    I want it to keep looping on all the sheets, but that delete action seems to kill the looping...

    What am I missing? Been grinding on this...


    Thanks.

  2. #2
    Forum Contributor
    Join Date
    08-27-2009
    Location
    South Africa
    MS-Off Ver
    Office 2010
    Posts
    217

    Re: Loop to Delete worksheets stops after deleting one sheet...

    Hi booDaddy

    and if you change
    If ws.Name <> "Parameters" And ws.Name <> "About" Then
    to

    If ws.Name <> "Parameters" OR ws.Name <> "About" Then
    If your Dreams don't scare you......They are not big enough

    If you like my answer don't forget to click on the *

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Loop to Delete worksheets stops after deleting one sheet...

    Is there other code in this workbook? The code you have posted is ok.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Delete rows without deleting title row using a loop
    By Sacharny in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2013, 01:00 PM
  2. [SOLVED] A Loop does not loop throught. It stops after two cells.
    By AB33 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2012, 01:14 PM
  3. Subroutine loop -- Stops after first, active sheet
    By za20001 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2011, 02:51 PM
  4. Do while loop to delete worksheets if worksheets are not in the specified list
    By kchm_2000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2011, 03:02 PM
  5. Do While Loop to Delete Worksheets
    By kchm_2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2011, 01:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1