Excel macro using Find function

Ken King 21 Reputation points

I am a novice in VBA and I am trying to create a complex (for me) macro for an Excel 2013 file.

I am trying to use the Find function and I am getting different results when I run the same macro a number of times.

When I first open the worksheets involved and run the following code it works.

Dim city As String
city = Range("C" & masrowno)
Cells.Find(What:=city, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

But at some point, while I am trying to perfect the rest of the macro, it stops working with either

Run-time error '91' most often OR
Run-time error '13' occasionally

Once I get the error I can't get it to run properly again.

I have used

Cells.Find AND

But again, once I get the error I can't get it to run properly again.

I have used Find in other very simple macros and don't have any problems.

What might I be missing in this macro?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,647 questions
0 comments No comments
{count} votes