Glitch in a code

Ahhhh

New Member
Joined
May 31, 2015
Messages
29
Hello Board,
So I have been working on a timer code that updates a sheet and repeats. It works just how I want it 60% of the time. Sometimes it works then skips an update then works again. Other times it continues to just skip the update.

Code:
Private Sub CommandButton1_Click()Dim t, E, M As Double, S As Double
t = Timer
AllowedTime = Int(Sheet1.Range("b1").Value)
Do
Application.EnableEvents = True
    If Timer - t < 0 Then
        Unload UserForm1
        MsgBox "Error encountered - start again"
        Exit Sub
    End If
    E = CDbl(Time) * 24 * 60 * 60 - t
    M = CDbl(AllowedTime) - 1 - Int(E / 60)
    S = 59 - Round((E / 60 - Int(E / 60)) * 60, 0)
    With tBx1
        .Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
    End With
    DoEvents
    If (Timer - t) / 60 = CDbl(AllowedTime) Then
    
        Range("A28").Value = Range("A28").Value + 1
        
        Range("B1").Value = "=VLOOKUP(A28,A2:E26,2,0)"
        Range("B1") = Range("B1")


        Range("C1").Value = "=VLOOKUP(A28,A2:E26,3,0)"
        Range("C1") = Range("C1")


        Range("D1").Value = "=VLOOKUP(A28,A2:E26,4,0)"
        Range("D1") = Range("D1")


        Range("E1").Value = "=VLOOKUP(A28,A2:E26,5,0)"
        Range("E1") = Range("E1")
        
        Range("B27").Value = "=VLOOKUP(A28+1,A2:E26,2,0)"
        Range("B27") = Range("B27")


        Range("C27").Value = "=VLOOKUP(A28+1,A2:E26,3,0)"
        Range("C27") = Range("C27")


        Range("D27").Value = "=VLOOKUP(A28+1,A2:E26,4,0)"
        Range("D27") = Range("D27")


        Range("E27").Value = "=VLOOKUP(A28+1,A2:E26,5,0)"
        Range("E27") = Range("E27")
        
        Range("G27").Value = "=(f27) & (G22*J22+G24*J24+G25*J25)"
        Range("G28") = Range("G27")
        
        Range("G26").Value = "=+G22*(K22+G24*K24+G25*K25)/G23"
        Range("G26") = Range("G26")
        
        
        
    End If
Loop Until (Timer - t) / 60 >= AllowedTime


Call CommandButton1_Click


End Sub

If you have any Ideas please let me know.
Thanks a bunch
 
Last edited by a moderator:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,215,730
Messages
6,126,527
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top