Option Explicit
Sub Estimated_time()
Dim StartValue
Dim StopValue
Dim percent5, percent10, percent20, percent50, percent80, percent95
Dim tStart, t1, t2, t3, timeleft
Dim mins, secs
Dim MyTimer
StopValue = 600
StartValue = 1
percent5 = (StopValue - StartValue) / 20
percent10 = (StopValue - StartValue) / 10
percent20 = (StopValue - StartValue) / 5
percent50 = (StopValue - StartValue) / 2
percent80 = (StopValue - StartValue) / 5 * 4
percent95 = (StopValue - StartValue) / 100 * 95
tStart = Timer
t1 = tStart
For StartValue = 1 To StopValue
If StartValue = CInt(percent5) Then
Start = 1
t2 = Timer
timeleft = (t2 - tStart) / 5 * 95
End If
If StartValue = CInt(percent10) Then
t2 = Timer
timeleft = (t2 - tStart) / 10 * 90
End If
If StartValue = CInt(percent20) Then
t2 = Timer
timeleft = (t2 - tStart) / 20 * 80
End If
If StartValue = CInt(percent50) Then
t2 = Timer
timeleft = (t2 - tStart)
End If
If StartValue = CInt(percent80) Then
t2 = Timer
timeleft = (t2 - tStart) / 80 * 20
End If
If StartValue = CInt(percent95) Then
t2 = Timer
timeleft = (t2 - tStart) / 95 * 5
End If
If Start = 1 Then
t3 = Timer
timeleft = timeleft + (t1 - t3)
t1 = t3
End If
mins = Fix(timeleft / 60)
secs = CInt(timeleft) - (mins * 60)
If secs < 10 Then
secs = "0" & secs
End If
Application.StatusBar = "Progress: " & Format(StartValue / StopValue, "Percent") & " Estimated time left " & mins & ":" & secs
MyTimer = Timer
Do
Loop While Timer - MyTimer < 0.03
Next StartValue
Application.StatusBar = False
End Sub
|