+ Reply to Thread
Results 1 to 11 of 11

Macro to delete rows with a Zero value. Macro seems to be in continual loop

  1. #1
    Registered User
    Join Date
    08-07-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Macro to delete rows with a Zero value. Macro seems to be in continual loop

    Hi all,

    As part of a macro i have created- I inserted a piece of code that I drafted from another forum:


    Please Login or Register  to view this content.
    I thought I would be able to just copy and paste it into my VBA code but it has cause my macro to get stuck and not finish.

    I have attached the entire macro code if this is required.
    Any legend out there have any ideas?

    Thanks.
    J
    Attached Files Attached Files
    Last edited by arlu1201; 08-07-2012 at 02:41 PM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,640

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    I'm no VBA man, but I think that instead of a loop you should use a filter on col B to filter all rows were cells have a 0 value and then delete the result

  3. #3
    Registered User
    Join Date
    08-07-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    Well i might have to resort to breaking my macro into two parts and manually deleting the zero values in between. But where is the fun in that. I want to conquer this- with the help of the forum of course...

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature.

    Try this code
    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    I have tried you code as it is in excel, and did not get any error, or failure. It deleted all cells with Column B value as 0

  6. #6
    Registered User
    Join Date
    08-07-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    How long did it take to run, i have it running here beside me for the last half an hour?

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    That is because you didnt decrease the LR value by 1 each time a row is deleted. If you do not do that, it will go on till it reaches the LR value.

    Did you try my code?

  8. #8
    Registered User
    Join Date
    08-07-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    Oh sorry I get you know, yes the code quoted above is ok. I had tested it myself. The problem seems to arise when i drop it into and existing macro i created through key strokes(attached).

    ---------- Post added at 07:00 PM ---------- Previous post was at 06:59 PM ----------

    I tried your code Arlu- thanks a million- but unfortunately it didnt work.

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    What are the steps performed by that macro? It has many select statements which you can do without.

    Maybe if you want to list out the steps, you can do that in a different thread and i can help you shorten it.

    ---------- Post added at 12:32 AM ---------- Previous post was at 12:31 AM ----------

    When you say it didnt work, what do you mean?

    Did it give you any error?

  10. #10
    Registered User
    Join Date
    08-07-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    Yes this is the strange thing- it doesnt give me any error. It just keeps running and not doing anything until i have had enough and close it down.

    Do you think, because there are no error messages, that it is just running extremely slow but will get there eventually?

    The macro without this inserted delete row function works perfectly and really fast. The problem is definitely with the delete function. Or maybe placed it in a silly place in the code?

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro to delete rows with a Zero value. Macro seems to be in continual loop

    It depends on what your code wants to do.

    Like i said, we can help you re-write the code if you tell us what are the steps you have taken.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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