Overflow error, but I can't get it to repeat it


Board Regular
Aug 14, 2016
A couple of months ago, I found some code online to create a delay when running VBA code, called SleepSub. I needed to use it because on Excel for Mac, some labels on my UserForms were not updating on the screen, even when I would use the Repaint method. (I think the labels were changing too fast for Excel to properly update them, though I never had that problem on Windows.) I found that if I called SleepSub on a Mac, the labels WOULD be updated on the screen.

On Excel 2011 for Mac, that sub just generated an overflow error. I have run this sub many times before without that error. What's worse is, I can't get it to repeat the error. Here's the full code of the sub:

Sub SleepSub(vSeconds As Variant)
'this sub will delay the code running for however many seconds are in vSeconds.

Dim t0 As Single, t1 As Single

t0 = Timer

    t1 = Timer
    If t1 < t0 Then t1 = t1 + 86400 'Timer overflows at midnight
    DoEvents    'optional, to avoid excel freeze while sleeping
Loop Until t1 - t0 >= vSeconds
End Sub
The sub is inside a standard module. I call the sub from within a UF module, like so:

Sub UpdateStatusLabel(PercentFinished As Integer)

Me.StatusLabel.Caption = PercentFinished & "% complete"
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL]  Mac Then
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]  If

End Sub
Anyone have any idea why I would sometimes receive an overflow error in SleepSub?


Well-known Member
Jul 14, 2010
did you try using double instead of single.
Can't really get my head around the issue completely, just this is the first thing that comes to mind.


Board Regular
Aug 14, 2016
I haven't tried that yet, but that's a good idea. I will make that change.

If anyone thinks of any other reason why it might be causing that error, I'm all ears. I wish there was a way to reproduce the error, but so far, it hasn't happened again, even with the variable types being Single.

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...