Noah Xu
Noah Xu

Reputation: 167

Find Function in VBA

I started a easy demo by writing

Sub search()
Range("B1:B7").Find("abc").Activate
End Sub

I was hoping that excel will auto select a cell contains value "abc" in it, however, I got an error message saying "object variable or with block variable not set". Did I miss anything at all please

Appreciate it.

Upvotes: 0

Views: 2248

Answers (1)

John Muggins
John Muggins

Reputation: 1198

"https://msdn.microsoft.com/en-us/library/office/ff839746.aspx"

    Sub tester()
    With Worksheets(6).Range("B1:B500")
        Set c = .Find("Smith Jon Junior", LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address ' not required
            c.Activate
        else
            msgbox ("Not Found")
        End If
    End With
End Sub

Upvotes: 2

Related Questions