2

I have code getting error 424 object required

lr = Range("O:O").Cells(Rows.Count, 1).End(xlUp).Row

For y = 0 To UBound(myVariable)
    a = myVariable(y)
    Range("O:O").Select
    Set objXL = GetObject(, "Excel.Application")
    Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    If z = "True" Then
        ActiveCell.Delete shift:=xlUp
    End If
    MsgBox z.Value
Next
Community
  • 1
  • 1
mahesh patil
  • 21
  • 1
  • 2

1 Answers1

1

Find retrieves an range Object. So you either:

a) Activate the found range

Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

OR

b) Assign the found range to a variable

Set z = Cells.Find(What:=a, After:=Range("O2"), LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)      'No .Activate in here '

Using both at the same time will produce an error.

NOTE:

Be carefull. If .Find does NOT find a match, it will retrieve Nothing. In such a case the .Activate will pop an error msg. So use some error handling in here.

CaBieberach
  • 1,748
  • 2
  • 17
  • 26