PDA

View Full Version : Solved: Progressbar



copyt
04-27-2012, 04:13 AM
Hello all, could you please help me to correct my code? The progress bar doesn't stop at 100%.

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



PS It would be great if you could also explain a bit about the correction.
Any help would be appreciated. :bow:

Teeroy
04-27-2012, 05:10 AM
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)

copyt
04-27-2012, 08:09 AM
@ Teeroy (http://www.vbaexpress.com/forum/member.php?u=44895)

Thank you very much for your correction and explaination. It's now working properly.