| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 
 | Sub verification_facture() 
Dim cellule As Range: Dim test As Boolean 
test = False 
 
For Each cellule In Range("D626") 
If (cellule.Value = "Rupture de Stock") Then 
test = True 
Exit For 
End If 
Next cellule 
 
If (test = True) Then 
MsgBox ("Des articles hors stock figurent dans la facture, il n'est pas possible de continuer") 
Exit Sub 
End If 
 
Dim ligne As Integer: ligne = 2 
Dim valeur_stock As Integer: valeur_stock = 0 
Dim valeur_demandée As Integer: valeur_demandée = 0 
Dim ref_cat As String: Dim ref_facture As String 
Dim choix_utilisateur As Byte 
 
While (Workbooks("catalogue.xlsx").Worksheets("Feuil1").Cells(ligne, 5).Value <> "") 
valeur_stock = Workbooks("catalogue.xlsx").Worksheets("Feuil1").Cells(ligne, 5).Value 
ref_cat = Workbooks("catalogue.xlsx").Worksheets("Feuil1").Cells(ligne, 3).Value 
 
 
For Each cellule In ThisWorkbook.Worksheets("facturation").Range("C6:C26") 
 
If (cellule.Value = ref_cat) Then 
valeur_demandée = ThisWorkbook.Worksheets("facturation").Cells(cellule.Row, 5) 
If (valeur_demandée > valeur_stock) Then 
MsgBox ("La référence..." & cellule.Value & "...ne possède pas assez de Stock") 
test = True 
End If 
End If 
Next cellule 
 
ligne = ligne + 1 
Wend 
If (test = True) Then 
Exit Sub 
 
Else 
choix_utilisateur = MsgBox("La facture semble correcte,souhaitez-vous l'imprimer et mettre à jour les stock??", vbYesNo) 
If (choix_utilisateur = 6) Then 
For Each cellule In thisworkbooks.Worksheets("facturation").Range("C6:C26") 
ligne = 2 
While (Workbooks("catalogue.xlsx").Worksheets("Feuil1").Cells(ligne, 5).Value <> "") 
If (cellule.Value = Workbooks("catalogue.xlsx").Worksheets("Feuil1").Cells(ligne, 3).Value) Then 
Workbooks("catalogue.xlsx").Worksheets("Feuil1").Cells(ligne, 5).Value = Workbooks("catalogue.xlsx").Worksheets("Feuil1").Cells(ligne, 5).Value - thisworkbooks.Worksheets("facturation").Cells(cellule.Row, 5).Value 
End If 
ligne = ligne + 1 
Wend 
Next cellule 
Else 
Exit Sub 
End If 
End If 
ThisWorkbook.Worksheets("facturation").PrintPreview 
End Sub | 
Partager