View Single Post
  #5   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 only edited the code a minimal amount. There are better ways of codeing
without the necessity of selecting but I won't confuse you with that.

I tested your code and sure enough it stops on the find if more than one not
found. I have no idea why. Anyway the modification fixes it.

I just comment out the on error lines but you can delete them. Also used a
few more line breaks so that the code does not break up in this post.

Sub MacroTestErrorHandling()

Dim foundCell As Range

Sheets("Source").Select
Range("A1").Select
Application.CutCopyMode = False
'On Error GoTo BillingDate
Set foundCell = Cells.Find(What:="Account Number", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)
If foundCell Is Nothing Then
GoTo BillingDate
Else
foundCell.Select
ActiveCell.Offset(1, 0).Copy
Sheets("Target").Select
Range("A2").Select
ActiveSheet.Paste
End If
'
BillingDate:
'On Error GoTo 0
'Err.Clear
Sheets("Source").Select
Range("A1").Select
Application.CutCopyMode = False
'On Error GoTo PaymentsReceived
Set foundCell = Cells.Find(What:="Billing Date", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)
If foundCell Is Nothing Then
GoTo PaymentsReceived
Else
foundCell.Select
ActiveCell.Offset(1, 0).Copy
Sheets("Target").Select
Range("B2").Select
ActiveSheet.Paste
End If
'
PaymentsReceived:
'On Error GoTo 0
'Err.Clear
Sheets("Source").Select
Range("A1").Select
Application.CutCopyMode = False
'On Error GoTo CorporateName
Set foundCell = Cells.Find(What:="Payment Received", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)

If foundCell Is Nothing Then
GoTo CorporateName
Else
foundCell.Select
ActiveCell.Offset(1, 0).Copy
Sheets("Target").Select
Range("H2").Select
ActiveSheet.Paste
End If
'
CorporateName:



End Sub


--
Regards,

OssieMac