Updating a cell during VBA execution

Mr930

Well-known Member
Joined
Aug 31, 2006
Messages
585
I have some lengthy VBA loops, and I am trying to display a counter in a cell. In each loop I have it place the counter in the cell. It works fine and updates as long as Excel has focus. However, if I go to another application, the cell is no longer updated, until the loop finishes and the Excel screen is updated.

Is there a way to have the cell be updated even if Excel loses focus?

thanks
Fred
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,252
Office Version
  1. 2016
Platform
  1. Windows
Try using DoEvents inside the loop.

Regards.
 

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,764
I find the trouble with placing a counter in a cell is that you need Screenupdating set to True which, in most cases, will slow down the execution of the code.

I usually inform the user of the macros progress via the statusbar. As far as I know, this will continue to update even if Excel loses its focus (I could be wrong tho')
 

Mr930

Well-known Member
Joined
Aug 31, 2006
Messages
585
How do you go about putting information in the status bar?

thanks
Fred
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
e.g.

Application.Statusbar = "30% done"

At the end

Application.Statusbar = False
 

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,764
How do you go about putting information in the status bar?

In terms of informing the user of the progress, I usually use a counter, e.g. (this would be within a Loop)

Code:
Application.StatusBar = "Finding policy " & n - 1 & " of " & End_Row - 1 & "..."

where n = row currently being processed, End_Row = end of data
 

Forum statistics

Threads
1,136,269
Messages
5,674,743
Members
419,525
Latest member
helensesc

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