QP School
Error handling in VBA - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48)
+--- Thread: Error handling in VBA (/showthread.php?tid=5230)



Error handling in VBA - Qomplainerz - 07-27-2023

Description:

Error handling helps prevent Excel from crashing when unexpected errors occur.

Example:

Sub ExampleErrorHandling()
    On Error GoTo ErrorHandler
    Dim result As Double
    result = 10 / 0 ' Division by zero will cause an error
    MsgBox "Result: " & result
    Exit Sub

ErrorHandler:
    MsgBox "An error occurred: " & Err.Description
End Sub