Tom
Tom

Reputation: 291

Trying to use. Find in VBA, getting error saying the object doest support the property or moethod

Here's the problem function. I've written lots of functions similar to this without issue and I've no idea what the problem is this time.

Sub FindEquipCost()
    Dim equipment As Range
    Set equipment = Sheets("Sheet1").Find("EQUIPMENT", 
     LookIn:=xlValues, MatchCase:=True)
    MsgBox (equipment)
End Sub

Upvotes: 1

Views: 50

Answers (1)

Vityata
Vityata

Reputation: 43595

As mentioned in the comments, Find() is a method of the Range object, not of the Worksheets object.

This is a way to run your code without an error:

Sub FindEquipCost()

    Dim equipment As Range
    Set equipment = Sheets("Sheet1").Cells.Find("EQUIPMENT", _
                                LookIn:=xlValues, MatchCase:=True)

    If Not equipment Is Nothing Then
        MsgBox equipment.Address
    Else
        MsgBox "MISSING"
    End If

End Sub

See the .Cells between Sheets() and .Find.

Upvotes: 1

Related Questions