{"id":12130,"date":"2012-02-29T13:46:40","date_gmt":"2012-02-29T13:46:40","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=1394"},"modified":"2022-08-07T00:35:38","modified_gmt":"2022-08-07T00:35:38","slug":"progressbar-in-excel-vba","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/02\/progressbar-in-excel-vba\/","title":{"rendered":"Progress Bar in Excel VBA"},"content":{"rendered":"
Progress bar is nothing but a placeholder, where you see the Progress of the operation which is getting performed.
\nLike Visual Studio there is NO already built progress bar in Excel Macro (VBA), which you can use it as an object and it will act like a Progress bar. But this is not a difficult task to create a Progress Bar in Excel Macro. In this article you are going to learn how to create\/simulate different types of Progress bar in Excel macro (VBA).
\nBasically as part of this article we are going to discuss following different kind of Progress bar:<\/p>\n
I believe this is the simplest way to show user the progress of your Excel Macro. For displaying and coding, both purposes it is very easy to use. Below is the Syntax to show the Progress of your Macro in Status Bar: <\/p>\n The above code will display the Dynamic Progress in % while Macro is running as shown below. Message you can customize yourself by changing the above Code. How to Show Progress in Status Bar<\/p><\/div> In Excel Macro, there is no already built Progress bar Control, which can directly be used just by dragging and putting it in User Form. Below are the Steps to create a Progress Bar in your Excel macro Code.<\/p>\n 1. Open one Excel Workbook \n How to Create Progress Bar : Add a User Form<\/p><\/div> 4. Now Change the Caption of the User Form as \u201cProcessing\u2026\u201d<\/p>\n \n How to Create Progress Bar : Add a User Form<\/p><\/div> 5. Add one Label Control from the Control Box and also change the Back Color of the Label in different Color.<\/p>\n <\/p>\n How to Create Progress Bar : Add a Label<\/p><\/div> 6. Remove the Caption of the label and keep it blank. <\/p>\n How to Create Progress Bar : Add a Label-2<\/p><\/div> 8. Now Double Click on the User Form and Copy \u2013Paste the below Code<\/p>\n <\/p>\n You are done with your Progress bar creation. Now you can activate the User Form at any point of time during your code and Progress Bar will start. Wherever you want to show this progress bar use the below statement: \n How to Create Progress Bar : Progress Bar<\/p><\/div> This can be achieved exactly the same way as we have done above. The only change will be in the code. You need to add one line to display the calculated % in Label Caption or User Form Caption.<\/p>\n The below highlighted line will display the Completed % dynamically. <\/p>\n You are done with your Progress bar creation. Now you can activate the User Form at any point of time during your code and Progress Bar will start. Wherever you want to show this progress bar use the below statement: This is how it will look while running the code:<\/p>\n \n How to Create Progress Bar : Progress Bar With %<\/p><\/div> <\/p>\n <\/p>\n
\n
\nApplication.StatusBar=<Your Message or Status here<\/i>><\/font>
\n
\nExample:<\/strong> Below is an example, which shows how to show Progress message in Status Bar of the Excel, when Macro is running.<\/p>\n\r\n\r\nSub ShowProgressInStatus()\r\n\tDim Percent As Integer\r\n\tDim PercentComplete As Single\r\n\tDim MaxRow, MaxCol As Integer\r\n\tMaxRow = 800\r\n\tMaxCol = 800\r\n\tPercent = 0\r\n\tFor irow = 1 To MaxRow\r\n\t\tFor icol = 1 To MaxCol\r\n\t\t\tWorksheets(\"Sheet1\").Cells(irow, icol).Value = irow\r\n\t\tNext\r\n\t\tPercentComplete = irow * icol \/ (MaxRow * MaxCol)\r\n\t\tApplication.StatusBar = Format(PercentComplete, \"0%\") & \" Completed\"\r\n\t\tDoEvents\r\n\tNext\r\n\tApplication.StatusBar = \"\"\r\nEnd Sub\r\n\r\n<\/code><\/pre>\n
\n
\n<\/a>
\n<\/p>\nSimple Progress Bar using User Control Form:<\/h2>\n
\n2. Press Alt+F11
\n3. Now Add a New User Form by Right Clicking on the Left side Project as shown below:<\/p>\n<\/a>
\n<\/p>\n<\/a>
\n<\/p>\n<\/a>
\n<\/p>\n
\n7. Now make the Size of the User Form same as the Label<\/p>\n<\/a>
\n<\/p>\n\r\n\r\nPrivate Sub UserForm_Activate()\r\n Call ShowProgressBarWithoutPercentage\r\nEnd Sub\r\n\r\n\r\nSub ShowProgressBarWithoutPercentage()\r\n\tDim Percent As Integer\r\n\tDim PercentComplete As Single\r\n\tDim MaxRow, MaxCol As Integer\r\n\tDim iRow, iCol As Integer\r\n\tMaxRow = 500\r\n\tMaxCol = 500\r\n\tPercent = 0\r\n'Initially Set the width of the Label as Zero\r\n\tfrmProgressBar.LabelProgress.Width = 0\r\n\tFor iRow = 1 To MaxRow\r\n\t\tFor iCol = 1 To MaxCol\r\n\t\t\tWorksheets(\"Sheet1\").Cells(iRow, iCol).Value = iRow * iCol\r\n\t\t\t\r\n\t\tNext\r\n\t\tPercentComplete = iRow \/ MaxRow\r\n\t\tfrmProgressBar.LabelProgress.Width = PercentComplete * frmProgressBar.Width\r\n\t\tDoEvents\r\n\tNext\r\n\tUnload frmProgressBar\r\nEnd Sub\r\n\r\n<\/code><\/pre>\n
\n <\/p>\nImportant: How to call this Progress Bar? <\/h2>\n
\n
\nfrmProgressBar.Show<\/i><\/font>
\n
\nWhile running, this is how your Progress Bar will look like.<\/p>\n<\/a>
\n<\/p>\nSimple Progress Bar with % Increment:<\/h2>\n
\r\n\r\nPrivate Sub UserForm_Activate()\r\n Call ShowProgressBarWithoutPercentage\r\nEnd Sub\r\n\r\n\r\nSub ShowProgressBarWithoutPercentage()\r\n\tDim Percent As Integer\r\n\tDim PercentComplete As Single\r\n\tDim MaxRow, MaxCol As Integer\r\n\tDim iRow, iCol As Integer\r\n\tMaxRow = 500\r\n\tMaxCol = 500\r\n\tPercent = 0\r\n'Initially Set the width of the Label as Zero\r\n\tfrmProgressBar.LabelProgress.Width = 0\r\n\tFor iRow = 1 To MaxRow\r\n\t\tFor iCol = 1 To MaxCol\r\n\t\t\tWorksheets(\"Sheet1\").Cells(iRow, iCol).Value = iRow * iCol\r\n\t\t\t\r\n\t\tNext\r\n\t\tPercentComplete = iRow \/ MaxRow\r\n\t\tfrmProgressBar.LabelProgress.Width = PercentComplete * frmProgressBar.Width\r\n frmProgressBar.LabelProgress.Caption = Format(PercentComplete, \"0%\")\r\n\t\tDoEvents\r\n\tNext\r\n\tUnload frmProgressBar\r\nEnd Sub\r\n\r\n<\/code><\/pre>\n
\n <\/p>\nImportant: How to call this Progress Bar? <\/h2>\n
\n
\nfrmProgressBar.Show<\/i><\/font>
\n <\/p>\n<\/a>
\n<\/p>\n If you need the Sample Workbook with Progress bar download it from here. If you are facing any issue in downloading it, please let me know.<\/h2>\n
<\/a>\n<\/div>\n