ub verification_stock()
    Dim ligne As Integer: ligne = 6
    Dim test As Boolean: test = False
    Dim ref_hs As String
    
    
'
'    For Each cellule In Range("C6:C26")
'        If cellule.Value <> "" Then test
'    Next cellule

Workbooks.Open Filename:="D:\Dropbox\YGGD\13. MEDIATHEQUE\FORMATION\VBA\BON BACHE - VBA\LIVRE - Apprendre VBA de façon ludique par la pratique\Sessions\08 facturation client automatisée - 2021 0301\Ressouces\catalogue.xlsx"
ThisWorkbook.Worksheets("facturation").Activate
Do While ThisWorkbook.Worksheets("facturation").Cells(ligne, 3).Value = ""
    If ligne = 26 And Cells(ligne, 3).Value = "" Then
        MsgBox "La facture ne comporte aucune saisie"
        test = True
            Exit Do
        Else
        If Cells(ligne, 3) = "" Then
            ligne = ligne + 1
        Else
            Exit Do
        End If
    End If
Loop


For Each cellule In ThisWorkbook.Worksheets("facturation").Range("F6:F26")
    If cellule.Value = "-" Then test = True: ref_hs = ref_hs & Cells(cellule.Row, 3).Value & ", "
Next cellule

Dim ref_cat As String
Dim valeur_stock, valeur_demandee As Integer
Dim reponse As Byte

ligne = 7

While Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 3).Value <> ""
    ref_cat = Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 3).Value
    valeur_stock = Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 6).Value
    For Each cellule In ThisWorkbook.Worksheets("facturation").Range("C6:C26")
        If cellule.Value = ref_cat Then
            valeur_demandee = ThisWorkbook.Worksheets("facturation").Cells(cellule.Row, 5)
            If valeur_demandee > valeur_stock Then
                test = True
                ref_hs = ref_hs & cellule.Value & ", "
            End If
        End If
        
    Next cellule
ligne = ligne + 1
Wend

If test = True Then
    MsgBox "les références suivantes ne disposent pas d'assez de stock :" & Chr(13) & Chr(10) & ref_hs & Chr(13) & Chr(10) & "Veuillez corriger"
    Exit Sub
Else
         
        
    reponse = MsgBox("Souhaitez-vous éditer la facture et effectuer la mise à jour des stocks", vbYesNo + question)
  
    If reponse = 6 Then
    
        For Each cellule In ThisWorkbook.Worksheets("facturation").Range("C6:C26")
            While Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 3) <> ""
                If Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 3) = cellule.Value Then
                    MsgBox cellule.Value
                    
                    Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 6).Value = _
                    Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 6).Value - _
                    ThisWorkbook.Worksheets("facturation").Cells(cellule.Row, 5).Value
                    MsgBox Workbooks("catalogue.xlsx").Worksheets("articles").Cells(ligne, 6).Value
                End If
            ligne = ligne + 1
            Wend
        Next cellule
        ThisWorkbook.Worksheets("facturation").PrintPreview
    End If
End If

            


End Sub