Resume Next not Resuming

ChuckDrago

Active Member
Joined
Sep 7, 2007
Messages
470
Office Version
  1. 2010
Platform
  1. Windows
Hi all,
I have a macro that loops through a list of items, locates them on another sheet via a FIND method and collects some data pertaining to the found item. It works well, except that it stops when the item is not found. To handle this, I used an On Error Resume Next statement, so that the item not found is skipped. And therein lies the issue... The Resume Next portion is not resuming.

The error code thrown is 91. The error setting in my computer is Break on unhandled errors. The macro stops via the End Sub below the inoperative Resume Next. Here is the related code:

Code:
 Range("A:A").Select
        On Error GoTo NotListed
        Selection.Find(What:=CurID, After:=ActiveCell, LookIn:=xlFormulas, _
             LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
             MatchCase:=False, SearchFormat:=False).Activate
             If Trap <> "Yes" Then...etc ,etc

and the Go To section is simply
Code:
NotListed:
     Trap = "Yes"
     On Error Resume Next
End Sub

The idea was to set the flag "Trap", so that the item not found is ignored and the loop moves to the next item (named CurID).
Any help will be appreciated as usual.
Chuck
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Rather than using error handling, it's best to prevent the error like
Code:
Dim Fnd As Range
Set Fnd = Range("A:A").Find(What:=CurID, After:=ActiveCell, lookIn:=xlFormulas, _
             LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
             MatchCase:=False, SearchFormat:=False)
If Not Fnd Is Nothing Then
   'value found so do something
End If
 
Upvote 0
Rather than using error handling, it's best to prevent the error like
Code:
Dim Fnd As Range
Set Fnd = Range("A:A").Find(What:=CurID, After:=ActiveCell, lookIn:=xlFormulas, _
             LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
             MatchCase:=False, SearchFormat:=False)
If Not Fnd Is Nothing Then
   'value found so do something
End If
Almost there, Fluff...and thanks for the assist. Now, what I need is to ACTIVATE the cell where CurID was found, so that I can extract data using ActiveCell.Offset(0,x). I wrote MsgBox ActiveCell.Address as the first statement after your find method and it yielded "$A$1" when the item was actually located at $A$5.
Thanks in advance,
Chuck
 
Upvote 0
It's best to avoid activating cells,so you could use
Code:
If Not Fnd Is Nothing Then
   MsgBox Fnd.Offset(1, 1).Value
End If
or using active cell
Code:
If Not Fnd Is Nothing Then
   Fnd.Select
   MsgBox ActiveCell.Offset(1, 1).Value
End If
 
Upvote 0
It's best to avoid activating cells,so you could use
Code:
If Not Fnd Is Nothing Then
   MsgBox Fnd.Offset(1, 1).Value
End If
or using active cell
Code:
If Not Fnd Is Nothing Then
   Fnd.Select
   MsgBox ActiveCell.Offset(1, 1).Value
End If
Works like a dream (used to be a nightmare!). Thanks a lot, Fluff.
Chuck
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top