Progress Bar

sepandb

Board Regular
Joined
May 25, 2009
Messages
141
I have a few different macros (ImportData, HideColumns etc.) that I want to display a progress bar for when those macros are run. I've read many different ways to do this when I search it on google but I would prefer to use the cleanest method where I can simply call the appropriate procedure for each different macro, without changing any of the other code of the progress bar. Any suggestions would be greatly appreciated.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Are progress bars only possible when you have a loop? Like is it impossible to make one for a procedure that simply hides the empty columns on my spreadsheet?
 
Upvote 0
Why do you need a progress bar for that? The code should be very fast.
 
Upvote 0
Why do you need a progress bar for that? The code should be very fast.

Its actually quite inconsistent and I am unsure why. Sometimes it is instantaneous, other times it takes 3-4 seconds. Also I have a macro where I update my headers/footers by copying cells from excel and that takes 3-4 seconds also and I would want progress bars for both.

This is the code for updating my headers/footers. Where can I update my progress bar given the following code? From what I understand, the code to update the progress bar/percentage complete needs to be embedded within the code of the actual procedure.

Code:
Sub CommandButton1_Click()
'Adding Headers/Footers to Control Valves, Shutoff Valves, SOV and Spare Parts

Application.ScreenUpdating = False

LastModified = Format(ThisWorkbook.BuiltinDocumentProperties("Last Save Time"), "mm/d/yyyy")


Sheet3.PageSetup.CenterHeader = Sheet2.Range("M4").Value & Chr(13) & Sheet2.Range("M5")
Sheet3.PageSetup.RightHeader = "Quotation #: " & Sheet2.Range("M6").Value & Chr(13) & "Rev. " & Sheet2.Range("M7").Value & ""
Sheet3.PageSetup.LeftFooter = "Quote Date: " & Sheet2.Range("M8") & Chr(13) & _
                             "Revision Date: " & LastModified
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You could do something like this (assumes you have added John Walkenbach's code).

Code:
Sub CommandButton1_Click()
'Adding Headers/Footers to Control Valves, Shutoff Valves, SOV and Spare Parts
Dim sb As clsProgressBar
Set sb = New clsProgressBar ' create a new progress bar
sb.Show "Please wait", vbNullString, 0 ' display the progress bar
Application.ScreenUpdating = False

LastModified = Format(ThisWorkbook.BuiltinDocumentProperties("Last Save Time"), "mm/d/yyyy")
sb.PercentComplete = 25
Sheet3.PageSetup.CenterHeader = Sheet2.Range("M4").Value & Chr(13) & Sheet2.Range("M5")
sb.PercentComplete = 50
Sheet3.PageSetup.RightHeader = "Quotation #: " & Sheet2.Range("M6").Value & Chr(13) & "Rev. " & Sheet2.Range("M7").Value & ""
sb.PercentComplete = 75
Sheet3.PageSetup.LeftFooter = "Quote Date: " & Sheet2.Range("M8") & Chr(13) & _
                            "Revision Date: " & LastModified
sb.PercentComplete = 100
Application.ScreenUpdating = True
Set sb = Nothing ' remove the progress bar
End Sub
 
Upvote 0
I get a "compile error: User-defined type not defined" at the line "Dim sb As clsProgressBar"

I have added Walkenbach's code. Thanks for your help
 
Upvote 0
With John Walkenbach's workbook open, go into the VBE, in the Project window open up Class Modules and double click clsProgressBar. File > Export and save somewhere handy. Then in your workbook, open the VBE, File > Import and import clsProgressBar.

Your code should now compile.
 
Upvote 0

Forum statistics

Threads
1,217,381
Messages
6,136,228
Members
450,000
Latest member
jgp19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top