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

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
308
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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:

Code:
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

Do
    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:

Code:
Sub UpdateStatusLabel(PercentFinished As Integer)

Me.StatusLabel.Caption = PercentFinished & "% complete"
Me.Repaint
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL]  Mac Then
    SleepSub(0.05)
[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?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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