View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Macro Error Handling

Hi Greg,

I trolled the internet looking for an answer to the On Error problem but did
not find anything. However, I did see a couple of suggestions that the below
example of code is the better way of handling errors and it works for your
code. (I am not advocating the use of the example code for Find. If I can
write code without using On Error then I prefer it and keep the On Error for
real errors because I have an extensive error routine that writes all the
info to a text file so that the user does not have to tell me what has
occurred.)

If you look up On Error Statement in VBA help it also says "The On Error
Resume Next construct may be preferable to On Error GoTo when handling
errors".

Anyway thought you might be interested.

On Error Resume Next
Cells.Find(What:="Account Number", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True).Activate
If Err.Number 0 Then
MsgBox "Account Number not found."
Err.Clear
On Error GoTo 0 'Required here
GoTo BillingDate
End If
On Error GoTo 0 'Also required here

--
Regards,

OssieMac