+ Reply to Thread
Results 1 to 10 of 10

Do - Loop (Sheet Delete Issue)

  1. #1
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Do - Loop (Sheet Delete Issue)

    Greetings,
    1- Open enclosed file.
    2- Run Macro1.
    Please Login or Register  to view this content.
    After running Macro1 you will see that there is an error on red line...

    Any support will be appreciated.
    Sub DontForgetThese()
         If Your thread includes any code Then Please use code tags...
         If Your thread has been solved Then Please mark as solved...
         If Anybody has helped to you Then Please add reputation...
    End Sub

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Do - Loop (Sheet Delete Issue)

    See if this works for you:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Do - Loop (Sheet Delete Issue)

    When you delete the worksheet, the object variable is disconnected from the object, so there is no ws.Next.

    As generally for deleting things, loop backwards:

    Please Login or Register  to view this content.
    Last edited by shg; 09-08-2014 at 01:13 PM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Do - Loop (Sheet Delete Issue)

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Do - Loop (Sheet Delete Issue)

    Sorry Harry

    You have defined ws as worksheet 1

    You then deleted worksheet 1

    Then you ask excel to switch to the next worksheet 1.

    Yes I can see why you would get an error.


    Please Login or Register  to view this content.

  6. #6
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Do - Loop (Sheet Delete Issue)

    Very thanks...Solved...

  7. #7
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Do - Loop (Sheet Delete Issue)

    Hi shg,
    There will be any diffrence if I use
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.
    ???

  8. #8
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Do - Loop (Sheet Delete Issue)

    There will be any diffrence if I use
    Yes.

    The first code will only have a positive match with: "apple"
    The second code with have a positive match with: "APPLE", "apple", "Apple", "APPle", etc

  9. #9
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Do - Loop (Sheet Delete Issue)

    Ok..
    What is InStr for ?

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Do - Loop (Sheet Delete Issue)

    using Instr will return a positive match with: "apple", "aaappleee", "this is an apple", "sappled", etc

+ 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. Loop to Delete worksheets stops after deleting one sheet...
    By booDaddy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2014, 05:12 PM
  2. [SOLVED] Delete Sheet before Importing Sheet calculation issue
    By aetedford in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-27-2013, 02:49 PM
  3. [SOLVED] Loop Through Sheet and Delete Rows
    By mlb723 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2012, 06:00 PM
  4. [SOLVED] Loop through entire sheet, Insert row, copy row data, paste row data, delete row
    By Hyperdude in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2012, 01:46 AM
  5. [SOLVED] Issue with For Each loop
    By ATLGator in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-16-2012, 09:01 PM

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