Progress Indicator for addition/subtraction of table rows

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi

I have this code that when run, either adds or removes a specific number of rows from table1 depending on cell value in A14
I am looking for way to show (as the code is running) a countdown(or countup) of how many rows are left to go.
It can be a cell on the sheet or a shape linked to a cell or pretty much anything like that.
It sometimes takes a while if a few rows are added and thought it might be better to show the progress.
The middle part of the code just shows a box with a statement about rows currently being added.
thanks

Rory

VBA Code:
 Dim i As Integer
 If Range("A14").Value > 0 Then
 For i = 1 To Range("A15").Value
 
 Application.ScreenUpdating = True
 ActiveSheet.Shapes("Rectangle: Rounded Corners 1").Visible = True
  Application.ScreenUpdating = False
ActiveSheet.ListObjects("Table1").ListRows.Add

Range("A20").Select
 ActiveSheet.Unprotect
    Selection.Insert Shift:=xlDown
    Next i
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You can use the statusbar:
VBA Code:
Application.Statusbar = "row " & i & " of " & Range("A15").Value
Although you would do better to assign the total number of rows to a variable.

It seems you are also adding single cells @ A20. And showing a rectangle with each loop. and selecting Range A20 with every loop. And changing App variables with each loop ...
Consider very well what needs to stay in the loop.
You may get some speedup by removing the range SELECT method like this:
VBA Code:
Range("A20").Insert Shift:=xlDown
 
Upvote 0
T
You can use the statusbar:
VBA Code:
Application.Statusbar = "row " & i & " of " & Range("A15").Value
Although you would do better to assign the total number of rows to a variable.

It seems you are also adding single cells @ A20. And showing a rectangle with each loop. and selecting Range A20 with every loop. And changing App variables with each loop ...
Consider very well what needs to stay in the loop.
You may get some speedup by removing the range SELECT method like this:
VBA Code:
Range("A20").Insert Shift:=xlDown

Thanks. Is there a way to get what is displayed in the status bar to be displayed in a shape or textbox. Something a bit more prominent than the bottom of the screen.

The shape i currently have basically displays some text to say rows are being added and to please wait...I didnt want people to be clicking like mad thinking nothing was happening :)
 
Upvote 0
Try this:
VBA Code:
ActiveSheet.Shapes("Rectangle: Rounded Corners 1").TextFrame2.TextRange.Characters.Text ="row " & i & " of " & Range("A15").Value
 
Upvote 0
You are turning off screen updating, so I am not sure if it's possible.
However, you can just change the text and color right before and revert back afterwards perhaps.

Edit: Another note, it is a terrible idea to slow down the code to update progress on each iteration. Maybe tie it to a Modula function.

Edit 2: With all the computation going, you may have to use DoEvents to let the update happen on the screen. On a userform you would use Me.Repaint.

Edit 3: Maybe you can just open a modeless userform with only a label that gives the information.

If i Mod 10 = 0 then update the progress
 
Last edited:
Upvote 0
T
You can use the statusbar:
VBA Code:
Application.Statusbar = "row " & i & " of " & Range("A15").Value
Although you would do better to assign the total number of rows to a variable.

It seems you are also adding single cells @ A20. And showing a rectangle with each loop. and selecting Range A20 with every loop. And changing App variables with each loop ...
Consider very well what needs to stay in the loop.
You may get some speedup by removing the range SELECT method like this:
VBA Code:
Range("A20").Insert Shift:=xlDown

Thanks. Is there a way to get what is displayed in the status bar to be displayed in a shape or textbox. Something a bit more prominent than the bottom of the screen.

The shape i currently have basically displays some text to say rows are being added and to please wait...I didnt want people to be clicking like mad thinking nothing was happening :)
You are turning off screen updating, so I am not sure if it's possible.
However, you can just change the text and color right before and revert back afterwards perhaps.

Edit: Another note, it is a terrible idea to slow down the code to update progress on each iteration. Maybe tie it to a Modula function.

Edit 2: With all the computation going, you may have to use DoEvents to let the update happen on the screen. On a userform you would use Me.Repaint.

Edit 3: Maybe you can just open a modeless userform with only a label that gives the information.

If i Mod 10 = 0 then update the progress
thanks for the info, however i have no idea how to do any of that. I have used userforms in the past but im not an expert with vba. :)
 
Upvote 0
T


Thanks. Is there a way to get what is displayed in the status bar to be displayed in a shape or textbox. Something a bit more prominent than the bottom of the screen.

The shape i currently have basically displays some text to say rows are being added and to please wait...I didnt want people to be clicking like mad thinking nothing was happening :)

thanks for the info, however i have no idea how to do any of that. I have used userforms in the past but im not an expert with vba. :)
Did you try the line from post #4 ?
 
Upvote 0
@bobsan42 It may be due to ScreenUpdating = False

Insert a new userform, and a label on it. Change ShowModal property to False.
1631799618814.png

Put this in Userform module so people can't close it with X:

VBA Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

    Cancel = True

End Sub

Instead of changing the shape text:

VBA Code:
Userform1.Show
Userform1.Label1.Caption = ="Please wait while the rows are being deleted! & chr(10) & "Row " & i & " of " & Range("A15").Value
Me.Repaint      ' might be needed, try without first
Userform1.Hide

Adjust the userform design to your liking. Also, best is to give userform and label more meaningful names.
 
Upvote 0
If you want to go the userform route, also change the "StartUpPosition" property to Manual (just 2 lines below in the image I posted). And in userform module:

VBA Code:
Private Sub UserForm_Activate()

    Me.Top = Application.Top + (Application.Height - Me.Height) / 2
    Me.Left = Application.Left + (Application.Width - Me.Width) / 2

End Sub

This will place the userform right in the center of Excel window. Userforms tend to show up in irrelevant places otherwise especially with multiple displays.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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