Sub OKCMDE()
Dim Sh As Worksheet, Typ As String
'on assigne le nom Sh à la feuille "Commandes"
Set Sh = Sheets("Commandes")
With Sheets("enregistrement commande")
Sh.Rows("5:5").Insert Shift:=xlDown, _
CopyOrigin:=xlFormatFromLeftOrAbove
'copies de enregistrement commande" vers "Commandes"
.Range("B8").Copy Sh.Range("B5")
.Range("D8").Copy Sh.Range("C5")
.Range("F8").Copy Sh.Range("D5")
.Range("H8").Copy Sh.Range("E5")
.Range("J8").Copy Sh.Range("F5")
.Range("B12").Copy Sh.Range("G5")
.Range("D12").Copy Sh.Range("I5")
.Range("F12").Copy Sh.Range("J5")
.Range("H12").Copy Sh.Range("K5")
.Range("J12").Copy Sh.Range("L5")
'Appels à la macro ChercheStock
'ChercheStock vérifie l'existence du stock
ChercheStock .Range("B16"), Sh.Range("M5")
ChercheStock .Range("D16"), Sh.Range("N5")
ChercheStock .Range("F16"), Sh.Range("O5")
ChercheStock .Range("H16"), Sh.Range("P5")
ChercheStock .Range("J16"), Sh.Range("Q5")
ChercheStock .Range("B20"), Sh.Range("R5")
ChercheStock .Range("D20"), Sh.Range("S5")
ChercheStock .Range("F20"), Sh.Range("T5")
ChercheStock .Range("H20"), Sh.Range("U5")
ChercheStock .Range("J20"), Sh.Range("V5")
ChercheStock .Range("B24"), Sh.Range("W5")
ChercheStock .Range("D24"), Sh.Range("X5")
.Select
Application.CutCopyMode = False
.Range("B24,B20,D20,F20,H20,J20,J16,H16,F16,D16,B16,B12,F12,H12,J12,J8,H8,F8,D8,B8").ClearContents
End With
End Sub
Sub ChercheStock(C As Range, D As Range)
Dim Stock As Variant
With Sheets("stock&tarifs")
' cheche le stock dans la plage C17:C28 à partir du libellé
Stock = Application.VLookup(C.Offset(-2), .[A17:C28], 3, 0)
'si le stock est suffisant, la commande est validée
If C <= Stock Then
D = C
Else
MsgBox (C.Offset(-2) & " quantité trop importante sortante")
End If
End With
End Sub