I have a major worksheet with a Macro that populates over two hundred columns sequentially. I need a Progress Bar that shows the end User how many of the columns have been completed.
I therefore created the simplified attachment to try and achieve that result, but without success.
Cols A and B on attached have one hundred dummy values drawn from ten sources.
Code below SHOULD open the Progress bar, which then moves as the total value from each source is added to columns L - U in turn.
Option Explicit
Dim b As Long, c As Long, f As Long, e As Long, s As Long
Dim i As Integer, j As Integer, pctCompl As Single
Sub MATRIX()
UserForm1.Show
Progress
With Sheet1
'Find last row with Data
f = .Cells(.Rows.Count, "A").End(xlUp).Row
If f < 3 Then f = 3
'Find last Column in sheet
e = .Cells(1, .Columns.Count).End(xlToLeft).Column
If e < 2 Then e = 2
'Count returns
For s = 12 To e
.Cells(2, s) = WorksheetFunction.SumIf(.Range(.Cells(2, 1).Address, .Cells(f, 1).Address), .Cells(1, s), .Range(.Cells(2, 2).Address, .Cells(f, 2).Address))
Next
End With
End Sub
Unfortunately the Code stops as soon as it calls the Progress Bar, even though my understanding was setting the Bar to "modeless" specifically did not stall the Main Code?
I am also not confident that the Bar code itself will update as each column is completed?
Sub Progress()
Dim i As Long, r As Long
With Prog_bar
'SET MIN value to 0
.ProgressBar1.Min = 0
'SET Max value to last column on sheet
r = .Cells(1, .Columns.Count).End(xlToLeft).Column
.ProgressBar1.Max = r
.Show vbModeless
i = ActiveCell.Column / r
'Change bar value to show the progress
.ProgressBar1.Value = i
'Display the percentage of task completed
.Caption = VBA.Format(i / Prog_bar.ProgressBar1.Max, "0%") & " Complete"
DoEvents ' DoEvents allows the UserForm to update.
End With
'Close bar when Macro finishes
Unload Prog_bar
End Sub
All solutions, suggestions and alternatives welcome as ever
Ochimus
Bookmarks