Sub SyntaxErrorDemo()
Dim x As Integer
x = 5 * (3 + 2)
End Sub
Sub RuntimeErrorDemo()
On Error Resume Next
Dim x As Integer, y As Integer
x = 10
y = 0
Debug.Print x / y
End Sub
Sub LogicErrorDemo()
Dim radius As Double, area As Double
radius = 5
area = 2 * 3.14159 * radius
Debug.Print "Area of the circle: " & area
End Sub
Sub ErrorHandlingDemo()
On Error GoTo ErrorHandler
'ERROR CAUSING CODE
Dim x As Integer, y As Integer
x = 10
y = 0
Debug.Print x / y
Exit Sub
'THE REST OF YOUR CODE
ErrorHandler:
Debug.Print "An error occurred. Please ensure you are not dividing by zero."
End Sub
Sub DebuggingDemo()
Dim i As Integer, sum As Integer
sum = 0
For i = 1 To 5
sum = sum + i
Debug.Print "Current sum after adding " & i & " is: " & sum
Next i
End Sub
On this page of the site you can watch the video online #12 How to Handle Errors and Debug Excel VBA Code with a duration of hours minute second in good quality, which was uploaded by the user Mindful Explorer 31 October 2023, share the link with friends and acquaintances, this video has already been watched 135 times on youtube and it was liked by 4 viewers. Enjoy your viewing!