I got code below. I am trying to learn about error handling in excel VBA.
Sub LoopErrorHandling()
Dim ws As Worksheet
Dim c As Range
On Error GoTo LoopErrorHandling_Err
Set ws = ThisWorkbook.Worksheets(1)
ws.Range("C1:C5").ClearContents
For Each c In ws.Range("A1:A5").Cells
c.Offset(0, 2).Value = c.Value / c.Offset(0, 1).Value
Next c
LoopErrorHandling_Exit:
On Error Resume Next
Set ws = Nothing
On Error GoTo 0
Exit Sub
LoopErrorHandling_Err:
MsgBox Err.Description
Resume Next
Resume LoopErrorHandling_Exit
End Sub
I want to understant the following in the above code.
- Should line
Set ws = Nothing
be coming after or before the lineLoopErrorHandling_Exit:
. - Shouldn't line
LoopErrorHandling_Err:
be enough, isLoopErrorHandling_Exit:
necessary. - What is the work of line
LoopErrorHandling_Exit:
in above code and does it triggers only if Error occurs. - Does above code covers everything what error handling needs in excel vba or is there stuff missing.