Chercher

Bonjour,

Je voudrais valider à l'aide d'un if si la valeur d'une cellule est trouvée dans une feuille. J'ai pensé à la fonction chercher (lorsqu'on fait contrôle F). J'ai enregistré le code avec l'enregistreur :

    Cells.Find(What:="salut", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate

Je voudrais valider si recherche envoie un résultat ou non. Par exemple si trouve , selectionner tes cellules, sinon autre cellule.

Avez-vous une idée.

Merci d'avance et bonne soirée

Bonsoir

Sans l'utilisation d'une variable

Sub test()
    If Not Cells.Find(What:="salut", After:=ActiveCell, LookIn:=xlFormulas, _
           LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
           MatchCase:=False, SearchFormat:=False) Is Nothing Then
      MsgBox "Trouvé"
    Else
      MsgBox "Perdu"
    End If
End Sub

Bonjour Banzai,

Merci de ta réponse. Le code fonctionne ! Que dois-je ajouter pour sélectionner la cellule trouvée?

Merci encore !


J'ai trouvé, j'ai simplement remis le code :

    If Not Cells.Find(What:=Range("P2"), After:=ActiveCell, LookIn:=xlFormulas, _
           LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
           MatchCase:=False, SearchFormat:=False) Is Nothing Then

    Cells.Find(What:=Range("P2"), After:=ActiveCell, LookIn:=xlFormulas, _
           LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
           MatchCase:=False, SearchFormat:=False).Activate

    Else
      MsgBox "Perdu"
    End If

Merci encore !

Rechercher des sujets similaires à "chercher"