+ Reply to Thread
Results 1 to 10 of 10

how to set up progress display for code that takes a long time

Hybrid View

kevinu how to set up progress... 05-23-2018, 01:26 PM
Fluff13 Re: how to set up progress... 05-23-2018, 01:33 PM
kevinu Re: how to set up progress... 05-23-2018, 02:57 PM
Fluff13 Re: how to set up progress... 05-23-2018, 03:00 PM
kevinu Re: how to set up progress... 05-24-2018, 10:20 AM
Fluff13 Re: how to set up progress... 05-24-2018, 10:25 AM
kevinu Re: how to set up progress... 05-24-2018, 10:41 AM
Fluff13 Re: how to set up progress... 05-24-2018, 10:51 AM
kevinu Re: how to set up progress... 05-24-2018, 10:58 AM
kevinu Re: how to set up progress... 05-24-2018, 05:14 PM
  1. #1
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    how to set up progress display for code that takes a long time

    I have a couple codes that delete a lot of data from my workbook but it takes almost 10 sec to complete. I'd like to put a progress tracker display of some sort that will let the user know its still working so they dont start clicking stuff or close it down thinking the program crashed. The code being used to delete data is this.

    Private Sub clearall_Click()
        'clears all data
       ' Application.ScreenUpdating = False
        With Sheet8
            .Range("a2:t71821").ClearContents
            .Range("w2:ad38959").ClearContents
            .Range("ag2:an38959").ClearContents
            .Range("aq2:ax38959").ClearContents
            .Range("ba2:bh38959").ClearContents
            .Range("Bl2:ca1899").ClearContents
        End With
        Sheet7.Cells.ClearContents
        Sheet14.Range("c5:e131").ClearContents
    I already have a progress bar for a different part of the program but it tracks progress by which array the code is using. In this code im not sure how to track which range its working on.

    I'm not sure if the other progress bar can be converted to be used here but its code is
     UserForm1.Show ' show progress form
        Dim pctCompl As Integer
        pctCompl = 0
        UserForm1.Text.Caption = pctCompl & "% Completed"
        UserForm1.Bar.Width = pctCompl * 2
        UserForm1.Repaint
        
        Application.ScreenUpdating = False
        Dim e
        For Each e In Array(Array("Connectivity suite", Range("c5")), Array("Connectivity suite", Range("y5")), Array("Connectivity suite", Range("au5")), Array("Connectivity suite", Range("bq5"))) 'position of large list scores and labels on symptoms & locations worksheet
               
            Application.ScreenUpdating = True
            UserForm1.LabelTitle = "Processing " & CStr(e(0))
            pctCompl = pctCompl + 25
            UserForm1.Text.Caption = pctCompl & "% Completed"
            UserForm1.Bar.Width = pctCompl * 2
            UserForm1.Repaint
            Application.ScreenUpdating = False

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,748

    Re: how to set up progress display for code that takes a long time

    That clearall code should not be taking 10sec to run.
    Do you have any event code on those sheets, or formulae looking at the ranges being cleared?

  3. #3
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how to set up progress display for code that takes a long time

    yes sheet8 has all the data that 20 other sheets look to for data anlaysis so there is a lot of computing going on when they change. I dont know if that can be changed.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,748

    Re: how to set up progress display for code that takes a long time

    In that case try adding the 2 lines in red
    Private Sub clearall_Click()
        'clears all data
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        With Sheet8
            .Range("a2:t71821").ClearContents
            .Range("w2:ad38959").ClearContents
            .Range("ag2:an38959").ClearContents
            .Range("aq2:ax38959").ClearContents
            .Range("ba2:bh38959").ClearContents
            .Range("Bl2:ca1899").ClearContents
        End With
        Sheet7.Cells.ClearContents
        Sheet14.Range("c5:e131").ClearContents
        Application.Calculation = xlCalculationAutomatic
    End Sub

  5. #5
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how to set up progress display for code that takes a long time

    thanks for the idea. Very cool, it makes the courser turn the the hour glass and wont let them click on stuff nice!
    Last edited by kevinu; 05-24-2018 at 10:25 AM.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,748

    Re: how to set up progress display for code that takes a long time

    Does it help if you ad these other 2 lines
    Private Sub clearall_Click()
        'clears all data
       Application.ScreenUpdating = False
       Application.Calculation = xlCalculationManual
       Application.EnableEvents = False
        With Sheet8
            .Range("a2:t71821").ClearContents
            .Range("w2:ad38959").ClearContents
            .Range("ag2:an38959").ClearContents
            .Range("aq2:ax38959").ClearContents
            .Range("ba2:bh38959").ClearContents
            .Range("Bl2:ca1899").ClearContents
        End With
        Sheet7.Cells.ClearContents
        Sheet14.Range("c5:e131").ClearContents
        Application.Calculation = xlCalculationAutomatic
        Application.EnableEvents = True
    End Sub

  7. #7
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how to set up progress display for code that takes a long time

    not noticing a huge improvement. It seems the screen is showing its done a little sooner but if i try to run something else it shows its still calculating stuff. I'm not sure if looking into speeding up the process is better than putting a progress bar. Although I love learning how to speed it up

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,748

    Re: how to set up progress display for code that takes a long time

    I've never used progress bars, so unfortunately cannot help any further.

  9. #9
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how to set up progress display for code that takes a long time

    not a problem I appreciate the advise on how to speed up the process.

  10. #10
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: how to set up progress display for code that takes a long time

    Found a way that works.. its ugly but it works. If anyone has a better way I'd love to see it.

    Private Sub clearall_Click()
    
    UserForm1.Show ' show progress form
        Dim pctCompl As Integer
        pctCompl = 0
        UserForm1.Text.Caption = pctCompl & "% Completed"
        UserForm1.Bar.Width = pctCompl * 2
        UserForm1.Repaint
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = False
        
        
        
            Application.ScreenUpdating = True
            UserForm1.LabelTitle = "Clearing FFT"
            pctCompl = pctCompl + 0
            UserForm1.Text.Caption = pctCompl & "% Completed"
            UserForm1.Bar.Width = pctCompl * 2
            UserForm1.Repaint
            
        
           
         Sheet8.Range("a2:t71821").ClearContents
         
      
           
            UserForm1.LabelTitle = "Clearing Coherence"
            pctCompl = pctCompl + 16.3
            UserForm1.Text.Caption = pctCompl & "% Completed"
            UserForm1.Bar.Width = pctCompl * 2
            UserForm1.Repaint
            
        Sheet8.Range("w2:ad38959").ClearContents
        
     
            
            UserForm1.LabelTitle = "Clearing Phase"
            pctCompl = pctCompl + 16.3
            UserForm1.Text.Caption = pctCompl & "% Completed"
            UserForm1.Bar.Width = pctCompl * 2
            UserForm1.Repaint
            
         Sheet8.Range("ag2:an38959").ClearContents
         
        
           
            UserForm1.LabelTitle = "Clearing Phase Lock"
            pctCompl = pctCompl + 16.3
            UserForm1.Text.Caption = pctCompl & "% Completed"
            UserForm1.Bar.Width = pctCompl * 2
            UserForm1.Repaint
            
         Sheet8.Range("aq2:ax38959").ClearContents
         
         
            
            UserForm1.LabelTitle = "Clearing Phase Shift"
            pctCompl = pctCompl + 16.3
            UserForm1.Text.Caption = pctCompl & "% Completed"
            UserForm1.Bar.Width = pctCompl * 2
            UserForm1.Repaint
           
          Sheet8.Range("ba2:bh38959").ClearContents
          
        
            
            UserForm1.LabelTitle = "Clearing Absolute Power"
            pctCompl = pctCompl + 16.3
            UserForm1.Text.Caption = pctCompl & "% Completed"
            UserForm1.Bar.Width = pctCompl * 2
            UserForm1.Repaint
           
        Sheet8.Range("Bl2:ca1899").ClearContents
       
        
        Sheet7.Cells.ClearContents
        Sheet14.Range("c5:e131").ClearContents
        Application.ScreenUpdating = False
        'Application.Calculation = xlCalculationAutomatic
        Unload UserForm1

+ 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] This code takes way to long to run
    By Jym396 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2017, 11:07 AM
  2. My macro takes a long time to run - need to speed it up or add a progress bar
    By songhaegyo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-07-2017, 08:17 AM
  3. [SOLVED] code ignore different spelling and takes a long time
    By torti111 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-04-2017, 05:14 AM
  4. [SOLVED] Translate code takes long time
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-28-2016, 12:58 AM
  5. Calculation takes long time
    By dorend in forum Excel General
    Replies: 10
    Last Post: 12-13-2011, 06:17 PM
  6. Long code takes an age to run
    By E3iron in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-05-2009, 07:38 AM
  7. display how long it takes to calc or timing certain events
    By GH in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-16-2005, 07:06 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