'fonction de recherche du combobox -------------------------------------------
intTopIndex = Me.ComboBox1.TopIndex
If Me.CheckBox4.Value = True Then
    Me.Label11.Visible = False
    Me.ComboBox2.Visible = False
    Me.TextBox1.Visible = False
    Me.T_Cherche.Visible = True
    Me.T_Cherche.Height = 73.55
    Me.T_Cherche.Left = 78
    Me.T_Cherche.Top = 45
    Me.T_Cherche.Width = 240
    Me.T_Cherche.Clear
    Dim result_combo As Boolean
    result_combo = False
        If Me.ComboBox1.text <> "" Then
            For Ligne = 2 To Feuil6.Cells.Find("*", , , , xlByRows, xlPrevious).Row
                If UCase(Feuil6.Cells(Ligne, 1).Value) Like "*" & UCase(Me.ComboBox1.text) & "*" Then
                    Me.T_Cherche.AddItem Feuil6.Cells(Ligne, 1).Value
                    Me.T_Cherche.ForeColor = &H0&         'noir
                    result_combo = True
                End If
            Next
            If result_combo = False Then
                    Me.T_Cherche.Clear
                    Me.T_Cherche.AddItem Feuil12.Cells(1350, 2).Value '"Aucun résultat"
                    Me.T_Cherche.ForeColor = &H808080  'gris
            End If
        End If
Else
    Me.T_Cherche.Visible = False
    Me.T_Cherche.Clear
End If
'fonction de recherche du combobox -------------------------------------------
If Feuil8.Range("P6").Value = "OUI" Then 'si codes-barres
    'If Len(Me.ComboBox1.Text) = "13" And Not Me.ComboBox1.Text Like "*-DP-*" And Not Me.ComboBox1.Text Like "*-Ref-DT*" Then
    If Not Me.ComboBox1.text Like "*-DP-*" And Not Me.ComboBox1.text Like "*-Ref-DT*" Then
                If Feuil8.Range("P13").Value = "OUI" And IsNumeric(Me.ComboBox1.text) Then
                    For m = 1 To Len(Me.ComboBox1.text)
                     ncd = ncd & trans(Mid(Me.ComboBox1.text, m, 1))
                    Next
                    Me.ComboBox1.text = UCase(ncd)
                    Beep 3000, 100  'chg
                    Me.ComboBox1.ForeColor = &H80FF&     'chg   'orange
                    Me.ComboBox1.Font.Bold = True        'chg
                    Me.Image13.BackStyle = fmBackStyleOpaque 'chg
                End If
                ligne_CB = Feuil5.Columns(2).Find("*", , , , xlByColumns, xlPrevious).Row 'dernière ligne de la colonne B
                'R = RechFind(Format(Me.ComboBox1.Text, "#""   ""00000""   ""000000"" ""#"), ThisWorkbook.Name, "PRODUITS", "E2:E" & ligne_CB, TB())
                R = RechFind(Me.ComboBox1.text, ThisWorkbook.Name, "PRODUITS", "E2:E" & ligne_CB, TB())
                    
                    If R > 0 Then
                        Me.ComboBox1.text = Feuil5.Cells(Range(TB(0)).Row, 1).Value
                        cd_b = Feuil5.Cells(Range(TB(0)).Row, 5).Value
                    End If
            If pass = False Then
                        If R > 1 Then
                            Me.img_Avertissement.Visible = True
                            pass = True
                        Else
                            Me.img_Avertissement.Visible = False
                        End If
            End If
    Else
            Me.ComboBox1.ForeColor = &H80000008         'noir  'chg
            Me.ComboBox1.Font.Bold = False                     'chg
            Me.Image13.BackStyle = fmBackStyleTransparent      'chg
    End If
End If
derncell = Feuil6.Cells.Find("*", , , , xlByRows, xlPrevious).Row
For j = 1 To derncell
    If Me.ComboBox1.text = Feuil6.Cells(j, 1).Value Or Me.ComboBox1.text & "-Ref-DT" = Feuil6.Cells(j, 1) Then
        If Me.ComboBox1.text Like "*-Ref-DT*" Or Me.ComboBox1.text Like "*-DP*" Or Me.ComboBox1.text & "-Ref-DT" = Feuil6.Cells(j, 1) Then
            don0 = Len(Me.ComboBox1.text)
            If Me.ComboBox1.text Like "*-Ref-DT*" Then don2 = don0 - 7
            If Me.ComboBox1.text Like "*-DP-*" Then don2 = don0 - 12
            If Not Me.ComboBox1.text Like "*-DP-*" And Not Me.ComboBox1.text Like "*-Ref-DT*" Then don2 = don0
            don3 = Left(Me.ComboBox1.text, don2)
            chain = don3 & "-Ref-DT"
            Set trouves = Feuil6.Cells.Find(What:=chain, LookAt:=xlWhole)
                If trouves Is Nothing Then
                 MsgBox "*******", vbCritical + vbOKOnly, "****"
                Else
                    lign1 = trouves.Row
                End If
        End If
        
        If Me.ComboBox1.text Like "*-Ref-DT*" Or Me.ComboBox1.text Like "*-DP-*" Or Feuil6.Cells(j, 1).Value Like "*-Ref-DT*" Then
                For d = lign1 + 1 To derncell + 1
                    If Not Feuil6.Cells(d, 1) Like "*" & don3 & "-DP-" & "*" Then
                        lign2 = d - 1
                        Exit For
                    End If
                Next
                        
            somm = Application.WorksheetFunction.Sum(Range(Feuil6.Cells(lign1, 3), Feuil6.Cells(lign2, 3))) 'quantité
            Me.Label28.Caption = somm
            Me.Label27.Visible = True
            Me.Label28.Visible = True
            
            mp_qtt_avt = Application.WorksheetFunction.Sum(Range(Feuil6.Cells(lign1, 3), Feuil6.Cells(lign2, 3))) 'quantité
            If Feuil6.Cells(lign1 + 1, 5).Value Like "*.*" Then
                Feuil6.Cells(lign1 + 1, 5).Value = Replace(Feuil6.Cells(lign1 + 1, 5).Value, ".", ",")
                Feuil6.Cells(lign1 + 2, 5).Value = Replace(Feuil6.Cells(lign1 + 2, 5).Value, ".", ",")
            End If
            mp_prx_avt = Feuil6.Cells(lign1 + 1, 5).Value 'prix 'prix
        
            Me.TextBox10.text = FormatV(Feuil6.Cells(lign1 + 1, 5)) 'prix
            Me.TextBox8.text = Feuil6.Cells(j, 3).Value   'quantité de la ligne de date
            Dim CodeBarre$
            If Feuil8.Range("P6").Value = "OUI" Then
                If Feuil5.Cells(j, 4).Value <> "" Then
                    Me.Label29.Visible = True
                    Me.Label29.Caption = Feuil5.Cells(j, 4).Value
                    Me.Label29.ControlTipText = Format(cd_b, "# ###### ######")
'                    CodeBarre$ = code128$(Feuil5.Cells(J, 4).Value)
'                    Me.Label30.Caption = CodeBarre$
                Else
                    Me.Label29.Visible = False
                End If
            End If
            Dim don4 As Integer
            Dim don5 As Integer
            Dim don6 As String
 
            If Me.ComboBox1.text Like "*-Ref-DT*" Or Feuil6.Cells(j, 1).Value Like "*-Ref-DT*" Then
                If combo = "press1" Then
                    Me.ComboBox2.text = Feuil6.Cells(lign1, 2).Value
                    Me.ComboBox1.text = Feuil6.Cells(lign1, 1).Value
                End If
            End If
            If Me.ComboBox1.text Like "*-DP-*" Then
                If combo = "press1" Then
                    Me.ComboBox2.text = Feuil6.Cells(j, 2).Value
                    Me.ComboBox1.text = Feuil6.Cells(j, 1).Value
                End If
            End If
        Else
            Me.Label27.Visible = False
            Me.Label28.Visible = False
            mp_prx_avt = Feuil6.Cells(j, 5).Value 'prix
            mp_qtt_avt = Feuil6.Cells(j, 3).Value 'quantité globale
                
            If Me.ComboBox1.text Like "*-Ref-DT*" Then
                Me.TextBox10.text = FormatV(Feuil6.Cells(lign1 + 1, 5)) 'prix
            Else
                Me.TextBox10.text = FormatV(Feuil6.Cells(j, 5)) 'prix
            End If
            
            If Feuil8.Range("P6").Value = "OUI" Then
                If Feuil5.Cells(j, 4).Value <> "" Then
                    Me.Label29.Visible = True
                    Me.Label29.Caption = Feuil5.Cells(j, 4).Value
                    Me.Label29.ControlTipText = Format(cd_b, "# ###### ######")
                Else
                    Me.Label29.Visible = False
                End If
            End If
            
            Me.TextBox8.text = Feuil6.Cells(j, 3)   'quantité de la ligne de date
            
            'If Me.TextBox8.Text = "0" And Me.ComboBox5.Text <> "P" Then
            If Me.TextBox8.text = "0" Then
                Me.TextBox10.Enabled = False
                Me.TextBox11.Enabled = False
                Me.Label10.Enabled = False
                Me.Label18.Enabled = False
                Me.Label14.Enabled = False
                Me.Label10.Enabled = False
            Else
                Me.TextBox10.Enabled = True
                Me.TextBox11.Enabled = True
                Me.Label10.Enabled = True
                Me.Label18.Enabled = True
                Me.Label14.Enabled = True
                Me.Label10.Enabled = True
            End If
            If combo = "press1" Then
                Me.ComboBox2.text = Feuil6.Cells(j, 2).Value
                Me.ComboBox1.text = Feuil6.Cells(j, 1).Value
            End If
           
            
        End If
     
        Me.TextBox1.text = Feuil6.Cells(j, 2)