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
 
Thank you both. You have given me lots of ideas to try as well as some things to try and speed the code up.

Bobsan..i managed to get post 4 to work and i quite like it...gives me some ideas now for other things I am doing.:) Im thinking now it might be better to have it as a percentage so ill have a play with that. I have the basics now.

Gokhan...I will give the userform a try, although i am going to have a break just now as my brain hurts. Im currently doing this on my laptop on my knee so i will wait until i get in front of my 3 monitors ( could never go back to one now :) ). I will update you with how I get on.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Reading skills ftw! As bobsan also reminded, you should have ScreenUpdating=False/True outside the loop. Those take time as well (approx. 10-20 ms each).
Shape.Visible should be outside as well.

Anything that doesn't need to happen each iteration should be outside really.
 
Upvote 0
@bobsan42 It may be due to ScreenUpdating = False

Insert a new userform, and a label on it. Change ShowModal property to False.
View attachment 47064
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.
Hi

I am getting this error

1631803932922.png
 
Upvote 0
Aww, I posted the code wrong, sorry for that. Wrote it here instead of VBA Editor.

VBA Code:
Userform1.Label1.Caption = "Please wait while the rows are being deleted!" & chr(10) & "Row " & i & " of " & Range("A15").Value
 
Upvote 0
Aww, I posted the code wrong, sorry for that. Wrote it here instead of VBA Editor.

VBA Code:
Userform1.Label1.Caption = "Please wait while the rows are being deleted!" & chr(10) & "Row " & i & " of " & Range("A15").Value
Cool. Got it working now.

Had to change me.repaint to userform1.repaint but its working well.

Im learning lots of cool stuff today! :)

Just of to firgure out how to display % now :)

thank you
 
Upvote 0
Had to change me.repaint to userform1.repaint but its working well.

Yes, if you are calling it from outside Userform's module, need to reference with its name.

Display % in numbers? Like:

VBA Code:
Userform1.Label1.Caption = "Please wait while the rows are being deleted!" & chr(10) & "Percent completed: " & Format (i / Range("A15").Value *100, "##0.00")
or percent left as:
VBA Code:
Userform1.Label1.Caption = "Please wait while the rows are being deleted!" & chr(10) & "Percent left: " & Format (1-i / Range("A15").Value *100, "##0.00")
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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