Hi Team,
I am trying to learn on Error goto Label,
Code is working ...... not sure whether its right approach.
Also can we Combine all labels at the end of code into if else stament to shorten code.
Err_First_Loop:
On Error Resume Next
MsgBox "Error in First Loop in cell " & c.Address, vbCritical
On Error GoTo 0
Exit Sub
[/CODE]
Below is a Sample data on which I am testing.
Thanks
mg
I am trying to learn on Error goto Label,
Code is working ...... not sure whether its right approach.
Also can we Combine all labels at the end of code into if else stament to shorten code.
Err_First_Loop:
On Error Resume Next
MsgBox "Error in First Loop in cell " & c.Address, vbCritical
On Error GoTo 0
Exit Sub
VBA Code:
[CODE=vba]Sub test()
Dim c As Range
On Error GoTo Err_First_Loop
For Each c In Range("a2:a4")
MsgBox c / 2
Next c
On Error GoTo Err_Second_Loop
For Each c In Range("c2:c4")
MsgBox c / 2
Next c
On Error GoTo Err_Third_Loop
For Each c In Range("e2:e5")
MsgBox c / 2
Next c
Exit Sub
Done:
Err_First_Loop:
On Error Resume Next
MsgBox "Error in First Loop in cell " & c.Address, vbCritical
On Error GoTo 0
Exit Sub
Err_Second_Loop:
On Error Resume Next
MsgBox "Error at Second loop in Cell " & c.Address, vbCritical
On Error GoTo 0
Exit Sub
Err_Third_Loop:
On Error Resume Next
MsgBox "Error at Third loop in Cell" & c.Address, vbCritical
On Error GoTo 0
End Sub
Below is a Sample data on which I am testing.
Book11 | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | Situation1 | Situation2 | Situation3 | ||||
2 | 20 | 20 | 20 | ||||
3 | #N/A | 90 | #N/A | ||||
4 | 60 | #N/A | 60 | ||||
5 | 88 | ||||||
Sheet1 |
Thanks
mg