Adding progress bar to code

  • Hi -
    I'm very new to VBA and wanted to add a progress bar to my script below. How would I go about adding one so I know how much of the job is completed

    Code

    ?



  • Re: Adding progress bar to code


    Short answer is don't, it adds unnecessary time to the execution of your code. VBA is only single threaded so you have to waste time updating a progress bar.
    If you're sure you want one though the quickest way to do it is through the status bar otherwise it gets a bit more complex.


  • Re: Adding progress bar to code


    Hi


    I would have to agree with Trunten. Progress bars add time to code. I think if you step back one step and say why am I wanting to add a progress bar. My first thought was the code is taking a long time that is why he wants a bar. So lets look at your code. It looks like you are wanting to delete cells with NA#.


    Do it all at once. It saves so much time you will gasp.


    This


    Code
    Sub GetRid()
    Range("A1", Range("A" & Rows.Count).End(xlUp)).AutoFilter 1, "#N/A"
    Range("A2", Range("A" & Rows.Count).End(xlUp)).EntireRow.Delete
    [a1].AutoFilter
    End Sub


    Take care


    Smallman

  • Re: Adding progress bar to code


    Hi Smallman -
    Yes, I am trying to delete all rows with a N/A in it. I used your script but it didn't work...It just filtered, but deleted everything else. I want to delete the N/As but keep everything else...



  • Re: Adding progress bar to code


    Thanks Trunten - This is helpful to see the code.


    Quote from trunten;705629

    Short answer is don't, it adds unnecessary time to the execution of your code. VBA is only single threaded so you have to waste time updating a progress bar.
    If you're sure you want one though the quickest way to do it is through the status bar otherwise it gets a bit more complex.


  • Re: Adding progress bar to code


    Hi


    The only time I don't proved a workbook is when I think that the procedure is too simple for anyone to get wrong. Here is the file which should help. I put a second procedure in to trap the fact that there may be no NA's but this is just to protect the headers. The only thing this procedure can delete is NA's, nothing else is possible.



    Take care


    Smallman

  • Re: Adding progress bar to code


    Hi Smallman - quick question for you. This script works well on smaller data sets, but once I start trying to use this on sets of data ranging from 100-500K it goes through the process of filtering, but nothing remains afterwards. I'm confused as to why it works on smaller data but not larger data sets. Any ideas on what I can do?

  • Re: Adding progress bar to code


    Hello


    You shouldn't apply that kind of looping code on a sheet containing that many rows. it's asking for troubles.

    Regards,


    Wigi


    Excel MVP 2011-2014


    For more Excel memes: visit http://www.wimgielis.com ==> English articles ==> Excel memes


    -- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!