0

I have taken over someone else's macro who has left the organisation. I get the following error as listed in the title with Run time error.

Below is the code it is telling me to debug. Problem is this is my first time to VBA macro's and I am unsure where to begin to solve the error.

Any help would be great as I can't go past this point.

Cells.Find(What:="Top 10 Rank", After:=ActiveCell, LookIn:=xlValues, _
       LookAt:=xlPart, SearchOrder:=xlByRows, _
       SearchDirection:= xlNext, MatchCase:=False, _
       SearchFormat:=False).Activate
1

2 Answers 2

1

If the value is not found in the search range then you will get an error, so it's best to split up your code into separate operations:

Dim f As Range
Set f = Cells.Find(What:="Top 10 Rank", After:=ActiveCell, LookIn:=xlValues, _
                   LookAt:=xlPart, SearchOrder:=xlByRows, _
                   SearchDirection:= xlNext, MatchCase:=False, _
                   SearchFormat:=False)

If Not f Is nothing Then
    'do somthing with f
Else
    Msgbox "not found!"
End If
Sign up to request clarification or add additional context in comments.

1 Comment

@MarkMeiring on Stack Overflow (and Stack Exchange in general) the best "thank you" is a checkmark. See that green checkmark icon under the up/down voting buttons? Give it some lovin', you'll get +2 for it and tell the world "this! this right here, look! this is the answer!"
1

No data was found, so .Find returned a null object reference (Nothing in VBA), as explained in this Microsoft Support page:

This macro error occurs because the Visual Basic Find method returns a NULL value which makes activating a cell impossible.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.