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:

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,138
Office Version
  1. 365
Platform
  1. Windows
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
 

ChuckDrago

Active Member
Joined
Sep 7, 2007
Messages
470
Office Version
  1. 2010
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,138
Office Version
  1. 365
Platform
  1. Windows
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
 

ChuckDrago

Active Member
Joined
Sep 7, 2007
Messages
470
Office Version
  1. 2010
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,138
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,940
Messages
5,598,975
Members
414,270
Latest member
skipolmsted

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
Top