Fonction recherche find

bonjour, j'aurai besoin d'aide pour ma fonction recherche , j'aimerai que ma macro recherche dans la colonne A, la reference écrite dans la cellule B2, si elle existe je met la cellule B2 en fond vert si elle n'existe pas je met la cellule en fond blanc, mais ma macro plante si quelqu'un peut m'aider merci.

Dim C As Range

Range("B2").Select

reference = ActiveCell.Value

Columns("A:A").Select

Set C = Selection.Find(What:=reference, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Activate

If C Is Nothing Then

Range("B2").Select

ActiveCell.Interior.Color = 2

Else

Range("B2").Select

ActiveCell.Interior.Color = 4

End If

End Sub

Bonjour,

à tester,

Sub CouleurVert()
Dim keywords As String, c As Range
Set plg = Range("A:A")
keywords = Range("B2")
  With plg
   .Interior.ColorIndex = xlNone
    Set c = .Find(keywords, LookIn:=xlValues, LookAt:=xlPart)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.Interior.ColorIndex = 43
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
 End With
End Sub
Rechercher des sujets similaires à "fonction recherche find"