-
Solved: Progressbar
Hello all, could you please help me to correct my code? The progress bar doesn't stop at 100%.
[VBA]Option Explicit
Sub Batchcalculation()
Application.ScreenUpdating = False
Dim finalrow As Long, _
i As Long
Dim PctDone As Single
Dim Counter As Integer
Worksheets("XLanalyzer").Activate
Counter = 1
finalrow = Cells(Rows.Count, 5).End(xlUp).Row
Worksheets("XLanalyzer").Cells(7, 5).Select
For i = 7 To finalrow
If Cells(i, 5) <> "" And Sheets("RawMS").Cells(4, 1) <> "" Then
Cells(i, 5).Activate
Worksheets("XLanalyzer").Range("G7:j10000").ClearContents
Worksheets("XLanalyzer").Range("G7").Value = ActiveCell.Value
Call MSMSRawData
Counter = Counter + 1
Else
MsgBox "Please upload MS data", vbCritical, "XLanalyzer Warning"
End If
PctDone = 2 * Counter / (finalrow)
With UserForm2
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents
Next i
Unload UserForm2
MsgBox "Done"
UserForm1.Show vbModeless
End Sub
[/VBA]
PS It would be great if you could also explain a bit about the correction.
Any help would be appreciated.
-
PctDone doesn't make sense to me (but it may in context with the other Sub call whose code is not included).
It appears that you want PctDone to show the progress through the For-Next loop. If this is the case then the following change should correct the 100% issue, is clearer and it makes the counter redundant:
PctDone = (i-7) / (finalrow-7)
-
@ Teeroy
Thank you very much for your correction and explaination. It's now working properly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules