awsumchillicrab
Board Regular
- Joined
- Jan 30, 2011
- Messages
- 56
Hi,
I have a code that GoTo a place called "Err_TrimSpaces" in event of error during a loop. After the loop is complete, I get the error "0". I found that if I put an "Exit Sub" before the Err_TrimSpaces, then my code will avoid that error. So my question is, how do I get my code to skip Err_TrimSpaces once the loop is complete so I can proceed to process more code - written as ABCDE below?
sub test()
Dim LastRow As Integer
LastRow = Range("a1").CurrentRegion.Rows.Count
Range("e1").Select
On Error GoTo Err_TrimSpaces
Do Until ActiveCell = Range("E" & LastRow)
ActiveCell = Trim(ActiveCell)
ActiveCell = Int(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
Exit Sub
Err_TrimSpaces:
If Err.Number = 13 Then 'data mismatch ie not number
Resume Next
Else
MsgBox Err.Number
End If
ABCDE
end sub
I have a code that GoTo a place called "Err_TrimSpaces" in event of error during a loop. After the loop is complete, I get the error "0". I found that if I put an "Exit Sub" before the Err_TrimSpaces, then my code will avoid that error. So my question is, how do I get my code to skip Err_TrimSpaces once the loop is complete so I can proceed to process more code - written as ABCDE below?
sub test()
Dim LastRow As Integer
LastRow = Range("a1").CurrentRegion.Rows.Count
Range("e1").Select
On Error GoTo Err_TrimSpaces
Do Until ActiveCell = Range("E" & LastRow)
ActiveCell = Trim(ActiveCell)
ActiveCell = Int(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
Exit Sub
Err_TrimSpaces:
If Err.Number = 13 Then 'data mismatch ie not number
Resume Next
Else
MsgBox Err.Number
End If
ABCDE
end sub