Methode Find avec Range

Bonjour à tous !

Cela fait 4h que je bloque alors je viens vers vous après de multiple essais je n'arrive pas a comprendre mon problème

Je cherche à trouve le nom sur plusieurs ligne sur la colonne A

image

Mon code :

Dim ligcherc As Range
Dim ligval as long

Set ligcherc = ActiveSheet.Range("A1:A5000").Find(What:="TEST2 TEST2", LookAt:=xlPart)

If Not ligcherc Is Nothing Then

ligval = ligcherc.Row

MsgBox ligval

End If

Mais cela donne rien, j'ai essayer de passer par l'enregistrement macro mais je ne comprend pas où je galère.

Cela marche si je met .cells au lieu du range

Mais voila mon code sur mon fichier principal :

Dim i As Integer
Dim ligcherc As Range
Dim ligAgent As Range
Dim ligCa As Range

Set wka = ThisWorkbook
Set wkb = Workbooks.Open(Application.ActiveWorkbook.Path & "\NomduFichier.xlsx", , True)

With wka.Sheets("BDD AGENTS")

    For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row

        If .Cells(i, "E").Value = "IDE" Then

        Set ligcherc = wkb.Sheets(1).Range("A1:A5000").Find(.Cells(i, "L").Value, LookAt:=xlPart)

            If Not lighcherc Is Nothing Then

            ligtrouve = ligcherc.Row 'Trouve la ligne du nom

'recherche seulement en dessous de celui ci le mot "CA"

            Set ligCa = wkb.Sheets(1).Range("A" & ligtrouve & ":A5000").Find(What:="CA", LookAt:=xlPart)

                If Not ligCa Is Nothing Then 'SI CA récupere la valeur de la derniere colonne de la ligne CA

                ligCAtrouve = ligCa.Row

                ligCAval = wkb.Sheets(1).Range(wkb.Sheets(1).Cells(ligCAtrouve, 1), wkb.Sheets(1).Cells(ligCAtrouve, wkb.Sheets(1).Cells(ligCAtrouve, Columns.Count).End(xlToLeft).Column)).Value

                MsgBox ligCAval 'Test du code

                End If

            End If

        End If

    Next i

End with

Le but est de trouver le nom, malgré que d'autres choses soient présentes dans la ligne.

Je vous joins le fichier.

Merci pour l'aide et le temps pris pour m'aider.

Hello,

Essaie comme ceci :

Set ligcherc = ActiveSheet.Range("A1:A5000").Find(What:="TEST2 TEST2", LookIn:=xlValues, LookAt:=xlPart)

Bonjour,

La message box ne renvoie rien donc pas l'impression que ça fonctionne.

Merci.

Bonsoir Starnain,

En retour fichier modifié pour ta demande.

Merci Cellus,

j'arrive à comprendre le code. J'ai l'impression que c'est au niveau du find que j'avais un bug.

Merci encore !

Bonjour,

Je ne comprend pas quand je met le code :

Set wka = ThisWorkbook

Set wkb = Workbooks.Open(Application.ActiveWorkbook.Path & "\DARStotalIDE.xlsx")

    For i = 2 To wka.Sheets("BDD AGENTS").Cells(Rows.Count, 1).End(xlUp).Row

        If wka.Sheets("BDD AGENTS").Cells(i, "E").Value = "IDE" Then

          str = wka.Sheets("BDD AGENTS").Cells(i, "L").Value

          With wkb.Sheets("tpsxbdroitsit1").Range("A1:A5000")

            On Error Resume Next

            c = .Find(str, , xlValues, xlPart, xlByRows).Row

            If c > 1 Then

            ligval = c: MsgBox "ligne: " & ligval

          End If

        End With

        End If

    Next i

Cela ne fonctionne pas.

Le code est sur un fichier et l'exécute sur l'autre fichier.

Merci pour l'aide apporté !

EDIT : Finalement j'ai trouvé problème sur la range ("A1:J5000") surement a cause de ces cellules fusionnées....

Rechercher des sujets similaires à "methode find range"