Search code examples
excelvbaruntimeonerror

Vba 'on error' handler does not appear to work


I am having difficulties trying to understand how basic ON ERROR handler works in VBA's excel (if at all). In the example below, I am dividing 6/0 expecting ON ERROR kick in, ie ignore the error-triggering line (y=6/0).

Sub UsingResumeNext()
    Dim x As Long, y As Long
    On Error Resume Next
    x = 6
    y = 6 / 0
    x = 7
End Sub

However when I run the code an pop up alert window comes up saying 'Runtime error 11, Division by zero',see attachment ( screenshot of an error ).

I am confused.. Should't the on error effectively 'silence' alert window from showing up? It looks like the on error handler does not work. Anyone has suggestion what I am doing wrong?


Solution

  • Check your VBE options, make sure you're not breaking on all errors:

    VBE Options / General tab