Hi, Tom Kreutz
Thank you for reaching out to Microsoft Q&A forum.
Sorry for you encountering this issue. The problem appears to be related to how Excel for Mac handles certain type conversions when combined with UI operations like Debug.Print or MsgBox.
The Issue
The overflow error occurs because of a bug in the Excel for Mac VBA runtime where:
- Using Integer and Single data types together
- Combined with UI operations (Debug.Print, MsgBox)
- Causes incorrect type handling that leads to overflow errors
Possible Workarounds
Here are several workarounds that should resolve the issue:
Solution 1: Change Data Types (Recommended)
Sub test()
Dim i As Long ' Change Integer to Long
Dim x As Double ' Change Single to Double
For i = 1 To 3
x = i
Debug.Print i & " " & x
Next i
End Sub
Solution 2: Use Explicit Type Conversion
Sub test()
Dim i As Integer
Dim x As Single
For i = 1 To 3
x = CSng(i) ' Explicit conversion
Debug.Print i & " " & x
Next i
End Sub
Solution 3: Use Variant Types
Sub test()
Dim i As Variant
Dim x As Variant
For i = 1 To 3
x = i
Debug.Print i & " " & x
Next i
End Sub
Solution 4: Add DoEvents
Sub test()
Dim i As Integer
Dim x As Single
For i = 1 To 3
x = i
Debug.Print i & " " & x
DoEvents ' Force UI refresh
Next i
End Sub
Best Practice
For maximum compatibility on macOS:
- Using Long instead of Integer (modern VBA handles Long more efficiently anyway)
- Using Double instead of Single for floating-point numbers
- Avoiding mixing different numeric types in assignments when possible
The first solution (using Long and Double) is your most reliable fix and is considered a VBA best practice regardless of platform.
Hope this helps. Feel free to get back if you need further assistance.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment."
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.