4

[M2 MacBook Air, macOS Sequoia 15.6.1 (24G90), Microsoft Excel for Mac Office 365 Version 16.102.1 (25101829)]

In a new .xlsm workbook, with Personal.xlsb removed and no plug-ins enabled (i.e. fresh Excel), post laptop reboot - when I run the following code I get:

Run-time error '6': Overflow"

...with line x = i highlighted.

The Immediate window shows "1 1".

If I enter the debugger and step through the code, it runs properly to completion. I'm totally flummoxed!

Sub test()
    Dim i As Integer
    Dim x As Single
    For i = 1 To 3
        x = i
        Debug.Print i & " " & x
    Next i
End Sub

BTW, this issue was cross-posted at: https://www.mrexcel.com/board/threads/excel-vba-strange.1276111/#post-6285937 and https://learn.microsoft.com/en-us/answers/questions/5600456/excel-vba-strange-runtime-error-6-overflow?page=1#answer-12314316

11
  • I couldn't replicate the error, have you tried declaring x and i as something different? (both as integer, both as long, ...) Commented Oct 28 at 7:20
  • How did you invoke Sub test()? Commented Oct 28 at 7:38
  • I also can't replicate. But one thing occurs to me: if the immediate window shows "1 1", that means that the loop executed once, so the error is happening on the second iteration. Have you tried stepping through in the debugger with a break on the line x = i and check what the value of i is? I suspect you are showing a cutdown example, and the error in your actual code lies elsewhere. Commented Oct 28 at 7:58
  • 6
    It's a Mac bug. Also posted here: mrexcel.com/board/threads/excel-vba-strange.1276111 Commented Oct 28 at 8:44
  • Plus one for Mr Excel Commented Oct 28 at 9:10

1 Answer 1

0

Two solutions to this problem can be found at https://learn.microsoft.com/en-us/answers/questions/5600456/excel-vba-strange-runtime-error-6-overflow?page=1&orderby=Helpful&comment=answer-12314719&translated=false#newest-answer-comment. The simplest is to add right after the Debug.Print statement:

    DoEvents  ' Force UI refresh
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.