Search code examples
excelvbaruntime-error

Ran into "Run-time error '6': Overflow " while trying to execute a function that would suppose to return error codes


I am new to VBA and currently facing this issue. When I tried to execute "PriErrCod()" function, the program ran into error saying it overflow. I don't quite understand how the error happened. Any answers and suggestions are welcome. Here is the function that I am trying to execute.

Option Explicit
Private Sub PriErrCod()
    Dim i As Integer
    Dim e
    Debug.Print "Here are the error codes ..."
    For i = 0 To 65535
        e = Error(i)
        If e <> "Application-defined or object-defined error" Then Debug.Print i & ": " & e
    Next i
End Sub

Solution

  • The type Integer does not support such a high number. Use Long instead and it will work.