Why does VBA "StatusBar" lag behind it's calls

Mackeral

Board Regular
Joined
Mar 7, 2015
Messages
232
Office Version
  1. 365
Platform
  1. Windows
I run this code to test how Status Bar works:
VBA Code:
     For I = 1 To 50
        For J = 1 To 500
            K = 4 + 4
        Next J
        Call Status_Bar("test", I, 50)
    Next I

This is the Status_Bar Code:
Code:
    Call Status_Bar("Test") ' Initializes.
    Stop
    For I = 1 To 50
        For J = 1 To 100
            K = 4 + 4
        Next J
        
        Call Status_Bar("Test", I, 50)
    Next I
    Stop
    Call Status_Bar("")  ' - To close

The Status Bar updates very slowly, and when I hit Esc then the whole of the Status Bar appears.
Shouldn't it go as fast as it's called?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You need to insert some DoEvents in the code so the background can catch up. For large jobs, I would test the iteration and update the status bar every 100 or so.
 
Upvote 0
VBA Code:
Dim L as long
For I = 1 To 50
        For J = 1 To 500
            K = 4 + 4
        Next J
       
        if I - L > 10 then
          Call Status_Bar("test", I, 50)
          DoEvents
          L = I
        End if
    Next I
 
Upvote 0

Forum statistics

Threads
1,215,223
Messages
6,123,727
Members
449,116
Latest member
Aaagu

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