I have a macro that takes a while to run and I would like to have a progress bar that pops up and shows what percentage is complete. I have created a user form and some code from what I was able to come up with by doing some research online but I cant get it to work. I believe it has to do with some of the variables in this code are already used in other ways in my macro and possibly I am putting it in the wrong location. I have tried many different ways and I am at a loss. Any help would be greatly appreciated.
I have attached my spreadsheet.
Here is the main code that I am trying to insert the progress bar into:
Enum ReadColumns
rcLineItem = 2
rcItemCode = 3
rcUnits = 6
rcSupplementalDescription = 4
rcUnitPrice = 5
rcOriginalPlanQuantity = 7
rcCurrentPlanQuantity = 8
rcCategory = 1
End Enum
Sub MergeandFillHeader()
Dim v As Variant, i As Long
Dim wb As Workbook, n As Long
With Application
.ScreenUpdating = False
.Calculation = xlAutomatic
End With
With ThisWorkbook
v = .Worksheets("Data").Range("C11").CurrentRegion.Value
For i = 3 To UBound(v)
If Not v(i, rcItemCode) = vbNullString Then
Set wb = Workbooks.Open(.Worksheets("Merge").Range("D5").Value & "\" & v(i, rcItemCode) & ".xlsm")
wb.Sheets(1).Copy After:=.Sheets(.Sheets.Count)
With .Sheets(.Sheets.Count)
.Cells(1, 4).Value = Worksheets("Merge").Range("D3").Value
.Cells(2, 4).Value = "=Data!A" & 8 + i
.Cells(3, 4).Value = "=Data!B" & 8 + i
.Cells(4, 4).Value = "=Data!C" & 8 + i
.Cells(5, 4).Value = "=Data!D" & 8 + i
.Cells(6, 4).Value = "=Data!E" & 8 + i
.Cells(7, 4).Value = "=Data!F" & 8 + i
.Cells(8, 4).Value = "=Data!G" & 8 + i
.Cells(9, 4).Value = "=Data!H" & 8 + i
End With
n = n + 1
wb.Close False
End If
Next i
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
Worksheets("Merge").Activate
MsgBox "Processed " & n & " files", Title:="Merge Excel files"
End Sub
I have been placing this code before "With ThisWorkbook" in the main code.
Progress.Bar.Width = 0
Progress.Show
For i = 1 To lastrow
pctdone = i / lastrow
With Progress
.Percent = "Processing Item" & i & "of" & lastrow
.Bar.Width = pctdone * (.ProgressBackground.Width)
End With
And I have been placing this after "next i" in the main code
If i = lastrow Then Unload Progress
Bookmarks