Hi.
When you use OnTime method you schedule number of calls to Scroll_row sub. the main sub Display_Scores will finish in a second or two (depends how many rows you have, i.e. Lr-11 number of rows). When it finish you have scheduled Lr-11 times runs of Scroll_Row macro, each of them separated in time by UpdateInterval2 seconds. So to cancel, you should cancel each individual scheduled run with the same statement that you used to schedule it and only last argument set to False. That's why I made the note.
As an alternative you can use recursion and make Scroll_Row schedule the next run. This way at any point of time you will have only one scheduled run. here is sample code:
Option Explicit
Dim UpdateInterval2 As Integer
Dim Lr As Long
Dim dRunTime As Date
Sub Display_Scores()
'Do Stuff
UpdateInterval2 = 5
Lr = Cells(Rows.Count, "B").End(xlUp).Row - 1
dRunTime = Now() + TimeSerial(0, 0, UpdateInterval2)
Application.OnTime dRunTime + TimeSerial(0, 0, UpdateInterval2), "Scroll_Row"
'Do more stuff
End Sub
Sub Scroll_Row()
If ActiveWindow.ScrollRow < Lr - 15 Then
If ActiveWindow.ScrollRow < 5 Then
ActiveWindow.ScrollRow = 5
Else
ActiveWindow.ScrollRow = ActiveWindow.ScrollRow + 1
End If
dRunTime = Now() + TimeSerial(0, 0, UpdateInterval2)
Application.OnTime dRunTime, "Scroll_Row"
End If
End Sub
I would recommend this approach. You can call off next run using the statement
Application.OnTime dRunTime, "Scroll_Row", Schedule:=False
Bookmarks