Macro Recherche Copier Coller ligne

Bonsoir,

Depuis 2 jours j'essaie de comprendre VBA mais j'ai un peu de mal à trouver ce que je veux faire sur les forums.

J'ai un ficher avec 2 onglets, un avec un tableau complet et un où je voudrais en tapant un nom dans la première colonne avoir directement la ligne qui correspond a ce nom depuis le tableau complet. Cette macro est faite pour gagner du temps en pas passer 5 min a faire ça à chaque fois que j'en ai besoin.

J'ai commencer à taper un code avec ce que j'ai pu voir mais j'ai du mal a faire la partie recherche.

Private Sub MaMacro()

Dim iBD As Long

Dim iSP As Long

Dim BD As Worksheet

Dim SP As Worksheet

Dim lig As Range

Dim xxx As String

Set BD = Worksheets("SynthesePatient")

Set SP = Worksheets("Basededonnées")

iSP = 3

For iBD = 2 To 10000

With SP

xxx = SP.Cells(iSP, 1).Text

lig = BD.Columns("A").Find(xxx, .Range("A2"), xlValues).Row

lig.Copy Destination:=SP.Range(iSP)

End With

iSP = iSP + 1

Next

End Sub

Je ne sais pas comment faire du coup je vous demande de l'aide.

Voilà je vous joins mon fichier afin d'être certainement plus clair sur ce que je veux faire.

Merci par avance

Clément.

48exemple.zip (99.02 Ko)

bonsoir,

une proposition

Sub MaMacro()

    Dim iBD As Long

    Dim iSP As Long

    Dim BD As Worksheet

    Dim SP As Worksheet

    Dim lig As Range

    Dim xxx As String

    Set SP = Worksheets("SynthesePatient")

    Set BD = Worksheets("Basededonnées")

    dlbd = BD.Cells(Rows.Count, 1).End(xlUp).Row
    dlsp = SP.Cells(Rows.Count, 1).End(xlUp).Row

    For iSP = 3 To dlsp
        With SP
            xxx = SP.Cells(iSP, 1)
            Set lig = BD.Range("A2:A" & dlbd).Find(xxx, LookIn:=xlValues, lookat:=xlPart) ' on peut remplacer xlpart par xlwhole s'il faut une correspondance sur le contenu de toute la cellule
            If Not lig Is Nothing Then
                BD.Rows(lig.Row).Copy Destination:=SP.Cells(iSP, 1)
            Else
                SP.Cells(iSP, i) = SP.Cells(iSP, 1) & " non trouvé"
            End If
        End With
    Next iSP

End Sub

Merci beaucoup ça marche !

Je te remercie c'est exactement ce que je voulais.

Merci d'avoir répondu aussi vite

Rechercher des sujets similaires à "macro recherche copier coller ligne"