Help on modifying vba for using Application StatusBar

kit99

Active Member
Joined
Mar 17, 2015
Messages
352
Found this example online:
Code:
Sub StatusBar()


'Code to monitor in StatusBar
For i = 1 To 10000
Worksheets("Ark1").Cells(i, 1).Value = i


'StatusBar
Application.StatusBar = "Macro is running...   Percentage complete is " & Round((i / 10000 * 100), 0) & "%"


Next


'StatusBar End
Application.StatusBar = ""


End Sub

If I understand this correctly, it declare a bit of work/code using the "i" and then puts the same "i" into the code for Application StatusBar telling the bar what bit of vba to monitor for progress...?

How can this bit of code be changed to be used in my code from this thread:
https://www.mrexcel.com/forum/excel...excel-2016-screen-flickering.html#post5049484

In my code I don't have just 1 line of calulation to monitor, but hundreds of lines doing different things.
My goal is to have a status bar that can monitor each stretch of code namned at the top (7 bits of code), Call ... SumSection, group1, and so on.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
What you could do is include a line at the top of each of your subs with the the statusbar displaying the name of the sub that is currently running.

Code:
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_SumSection"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group1"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group2"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group3"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group4"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group5"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group6"

Then at the bottom of the last part of your code reset the statusbar with Application.StatusBar = False

You could also incorporate a timer to indicate how long it took to run:

Code:
Sub PG_1_OppdatereALT()


    Dim StartTime As Double
    Dim MinutesElapsed As String
    
    StartTime = Timer
    
    Call KIT_1_OppdatereALT_SumSection
 
    Call KIT_1_OppdatereALT_group1
    Call KIT_1_OppdatereALT_group2
    Call KIT_1_OppdatereALT_group3
    Call KIT_1_OppdatereALT_group4
    Call KIT_1_OppdatereALT_group5
    Call KIT_1_OppdatereALT_group6
    
    MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss")
    MsgBox "Finished successfully in " & MinutesElapsed, vbInformation
[COLOR=#333333][FONT=Verdana]    Application.StatusBar = False[/FONT][/COLOR]
               
End Sub
 
Last edited:
Upvote 0
What you could do is include a line at the top of each of your subs with the the statusbar displaying the name of the sub that is currently running.

Code:
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_SumSection"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group1"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group2"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group3"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group4"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group5"
    Application.StatusBar = "Currently running: KIT_1_OppdatereALT_group6"

Then at the bottom of the last part of your code reset the statusbar with Application.StatusBar = False

You could also incorporate a timer to indicate how long it took to run:

Code:
Sub PG_1_OppdatereALT()


    Dim StartTime As Double
    Dim MinutesElapsed As String
    
    StartTime = Timer
    
    Call KIT_1_OppdatereALT_SumSection
 
    Call KIT_1_OppdatereALT_group1
    Call KIT_1_OppdatereALT_group2
    Call KIT_1_OppdatereALT_group3
    Call KIT_1_OppdatereALT_group4
    Call KIT_1_OppdatereALT_group5
    Call KIT_1_OppdatereALT_group6
    
    MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss")
    MsgBox "Finished successfully in " & MinutesElapsed, vbInformation
[COLOR=#333333][FONT=Verdana]    Application.StatusBar = False[/FONT][/COLOR]
               
End Sub


This was very useful indeed! By doing it this way, I don't even have to limit myself to one statusbar-info for each section/group-run. I can put the same info into other parts of my code, giving me information on progress inside each section/group-run as well.
Fantastic! :)
Thanks a lot for responding to my thread, and thanks for your suggestions/tips!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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