Correction code RechercheV sur plusieurs lignes HELP !!!

PEX

XLDnaute Occasionnel
bonjour a tous,

je m'explique : mon soucis vient du faite que pour un produit j'ai plusieurs date ( differente ligne car incrementation ). Lors de ma recherche seul les cellules appartenant a la ligne ou il y a le nom apparaisse dans ma recerche.
c'est un peu complexe a expliquer mais je vous laisse un fichier en piece jointe pour que vous compreniez !

merci car je planche dessus depuis plusieurs jours.

Code:
Private Sub Label_Alerte_Click()

End Sub

Private Sub quit_Click()
Label_Alerte = ""
Unload Me

End Sub
Private Sub UserForm_Initialize()

Dim lf As Long 
Sheets("Primaire").Select
lf = Range("A65536").End(xlUp).Row 
CBrecherche.Clear 
For Each cel In Range("A2:A" & lf) 
If cel.Value <> "" Then CBrecherche.AddItem cel.Value
Next cel 
    
End Sub
Private Sub save_Click()

    Dim X As Integer
    Dim R As Range
    Dim ligne, occurence As Long
    Dim trouve As Boolean 'déclare la variable trouvé
    

        
        trouve = False
        occurence = 0
        ligne = 2
        Label_Alerte = ""
               
        '=======================================================
         '=======================================================
        Set R = ThisWorkbook.Sheets("primaire").Range("A:A").Find(what:=CBrecherche.Value, LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlNext)
        If Not R Is Nothing Then 'condition si au moins une occurrence trouvée
            trouve = True
            For Each R In ThisWorkbook.Sheets("primaire").Range("A65536:A" & ThisWorkbook.Sheets("primaire").Range("A:A").End(xlDown).Row)
                If R.Value = CBrecherche.Value Then
               With ThisWorkbook
               
                         If occurence = 0 Then
                            .Sheets("recherche").Range("A" & ligne).Value = .Sheets("primaire").Range("A" & R.Row).Value
                            .Sheets("recherche").Range("B" & ligne).Value = .Sheets("primaire").Range("B" & R.Row).Value
                            .Sheets("recherche").Range("C" & ligne).Value = .Sheets("primaire").Range("C" & R.Row).Value
                            .Sheets("recherche").Range("D" & ligne).Value = .Sheets("primaire").Range("D" & R.Row).Value
                            .Sheets("recherche").Range("E" & ligne).Value = .Sheets("primaire").Range("P" & R.Row).Value
                            .Sheets("recherche").Range("F" & ligne).Value = .Sheets("primaire").Range("Y" & R.Row).Value
                            .Sheets("recherche").Range("G" & ligne).Value = .Sheets("primaire").Range("Z" & R.Row).Value
                            End If
                            .Sheets("recherche").Range("H" & ligne).Value = .Sheets("primaire").Range("R" & R.Row).Value
                            .Sheets("recherche").Range("I" & ligne).Value = .Sheets("primaire").Range("S" & R.Row).Value
                            .Sheets("recherche").Range("J" & ligne).Value = .Sheets("primaire").Range("T" & R.Row).Value
                        occurence = occurence + 1
                        ligne = ligne + 1
                      

                         End With
                       End If
                       Next
                End If
            
        
      
        
        If trouve = False Then
            Label_Alerte = "Aucune information trouvée"
        Else
            ThisWorkbook.Sheets("recherche").Activate
            Unload Me
End If

    
End Sub

Cordialement

Pex
 

Pièces jointes

  • Gestion Primaire.xlsm
    61.9 KB · Affichages: 49
  • Gestion Primaire.xlsm
    61.9 KB · Affichages: 49
  • Gestion Primaire.xlsm
    61.9 KB · Affichages: 59

Membres actuellement en ligne

Statistiques des forums

Discussions
312 215
Messages
2 086 329
Membres
103 184
dernier inscrit
Di Martino