Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:34:36+00:00 2026-06-07T22:34:36+00:00

I found an Excel VBA script and tutorial, except it doesn’t really break the

  • 0

I found an Excel VBA script and “tutorial”, except it doesn’t really break the code, and the bar code into separate sections.

http://spreadsheetpage.com/index.php/tip/displaying_a_progress_indicator/

The script attached to the “demo” adds random numbers into an excel sheet, as the progress bar goes across.

What this code on the sheet doesn’t do is break the sections up, so saying ‘ this is the code for the random numbers, and ‘ this is the code for the actual progression bar.

Could someone disect this code and make it more “user friendly” for those who can’t speak VBAeese as well as those who seemed to of written it?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:34:39+00:00Added an answer on June 7, 2026 at 10:34 pm

    Here is a heavily commented version of the code for you:

    Sub Main()
    '   Inserts random numbers on the active worksheet
        Dim Counter As Integer
        Dim RowMax As Integer, ColMax As Integer
        Dim r As Integer, c As Integer
        Dim PctDone As Single
    
    
        If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
        '- if this subroutine is ran on a sheet that is not called "Worksheet" then exit
        '-- change 'Worksheet' to whatever sheet you want the progress bar on
    
        Cells.Clear
        '- clear all cells in active worksheet
    
        Application.ScreenUpdating = False
        '-disables updating the screen in the for loop that follows
        '- that way if we are editing 1000 cells int he workbook it only needs to update them at the end when
        '- this is set back to true
    
        Counter = 1 '- counter counts what cell we are on
        RowMax = 100 '- this is how many rows will be filled with data
        ColMax = 25 '- this is how many columns will be filled with data
    
        '- note that Rowmax * ColMax = 2,500 co counter will go from 1 to 2,500
    
        For r = 1 To RowMax
            '-for each row 1 to 100 we will loop through the 25 columns to add the random number
            For c = 1 To ColMax
                '- enter a random number into the cell we are on (Cells(r,c))
                Cells(r, c) = Int(Rnd * 1000)
                '- +1 to the coutner so we can count which cell we ar eon out of 2,500
                Counter = Counter + 1
            Next c
            '- after finishing each column but before starting the next row
            '- check what percent done we are (to update the userform)
            PctDone = Counter / (RowMax * ColMax)
    
            '- Edit the progressbar called "UserForm1" (already exists in workbook)
            With UserForm1
                'Userform has 2 items in it a Label called 'FrameProgress' and a onject called 'LabelProgress'
                'Change the text in the Label called 'FrameProgress' to display the percent done we calculated earlier
                .FrameProgress.Caption = Format(PctDone, "0%")
                ' Resize the object called 'LabelProgress' to be X perxent of the width of the previous label (minus 10 to leave room on the edge)
                ' - where X is the percent we are done
                .LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
            End With
    '       The DoEvents statement is responsible for the form updating
            DoEvents
        Next r
        '- exit form when it is at 100%
        Unload UserForm1
    End Sub
    

    the only parts of the code that are useful to you are to note that while it is looping it is figuring out what percent it is done, then using that to update the form.

    If you had a lot of code you could simply put the follwoing throughout it (assuming you build the form)

    Sub Example()
        'wait a few seconds
        Application.Wait (100000)
        'your code goes here instead of .wait
    
        PctDone = 0.3
        With UserForm1
            'Userform has 2 items in it a Label called 'FrameProgress' and a onject called 'LabelProgress'
            'Change the text in the Label called 'FrameProgress' to display the percent done we calculated earlier
            .FrameProgress.Caption = Format(PctDone, "0%")
            ' Resize the object called 'LabelProgress' to be X perxent of the width of the previous label (minus 10 to leave room on the edge)
            ' - where X is the percent we are done
            .LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
        End With
        'The DoEvents statement is responsible for the form updating
        DoEvents
    
        Application.Wait (100000)
        'your code goes here instead of .wait
    
        PctDone = 0.6
        With UserForm1
            .FrameProgress.Caption = Format(PctDone, "0%")
            .LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
        End With
        DoEvents
    
        Application.Wait (100000)
        'your code goes here instead of .wait
    
        PctDone = 0.9
        With UserForm1
            .FrameProgress.Caption = Format(PctDone, "0%")
            .LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
        End With
        DoEvents
    
        Application.Wait (100000)
        'your code goes here instead of .wait
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to translate the VBA code found in this link into IronPython.
i am reading an excel file using this code i found over the net:
I've found a problem in Excel/VBA in the Worksheet_Change Event. I need to assign
I've got some old Excel VBA code where I want to run a task
I want to change these lines in my excel VBA code to something much
I'm new to Perl and want to plot a chart using Excel. I found
So, to preface, I'm a complete novice at this Excel business. I've found similar
found this little code snippet that seems to do what i want, but im
Using Excel 2007 VBA Have a sheet Dashboard, have other sheets but some special
In VBA / VB.NET you can assign Excel range values to an array for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.