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

Mackeral

Board Regular
Joined
Mar 7, 2015
Messages
141
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?
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
1,830
Office Version
  1. 365
Platform
  1. Windows
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.
 

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
1,830
Office Version
  1. 365
Platform
  1. Windows
Screen updates are lower priority than iterations and calculations.
 

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
1,830
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,925
Members
414,416
Latest member
Nobu

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
Top