Private Sub CmdEnregister_Click()
With Application
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
.StatusBar = False
End With
If Client = "" Then MsgBox "Vueillez saisir le client.", , "Les Milles Merveilles": _
Article.SetFocus: Exit Sub
If Representant = "" Then MsgBox "Vueillez saisir votre nom.", , "Les Milles Merveilles": _
Article.SetFocus: Exit Sub
With Sheets("Archives")
lig = .Range("a65536").End(xlUp).Row + 1
.Range("a" & lig) = lig - 1
.Range("b" & lig) = Format(CDate(DateCom), "dd.mm.yyyy")
.Range("c" & lig) = Format(Val(NmCom), "0")
.Range("d" & lig) = Article
.Range("e" & lig) = Format(Val(Quantite), "0")
.Range("f" & lig) = Format(Val(Prix), "0.00")
.Range("g" & lig) = Format(Val(Rabais) / 100, "0%")
.Range("h" & lig) = Format(Val(DifMontant), "0.00")
.Range("i" & lig) = Format(Val(Montant), "0.00")
End With
With Sheets("Bon de Commande")
derlig = .Range("c" & Rows.Count).End(xlUp).Row
Set plage = .Range("c2:c" & derlig)
Clt = Application.Match(Client, WsCl.Columns(2), 0)
Rep = Application.Match(Representant, WsRep.Columns(2), 0)
x = 17
Set cel = plage.Find(NmCom, , xlValues)
If Not cel Is Nothing Then
premaddress = cel.Address
WsBC.Range("g2") = Format(Val(NmCom) - 1400, "0")
Do
x = x + 1
rw = Application.Match(cel.Offset(0, 1), WsProd.Columns(3), 0)
.Range("b" & x) = WsProd.Cells(rw, 2) 'Code article
.Range("c" & x).Value = cel.Offset(0, 1).Value 'Article
.Range("d" & x).Value = cel.Offset(0, 2).Value 'Quantité
.Range("e" & x).Value = cel.Offset(0, 3).Value 'Prix
.Range("f" & x).Value = cel.Offset(0, 5).Value 'Rabais
.Range("g" & x).Value = cel.Offset(0, 6).Value 'Total
.Range("g45") = WorksheetFunction.Sum(.Range("g18:g40"))
.Range("g46") = ((.Range("g45") * 0.08) * 100) / 100 ' Rabais
.Range("g4") = Format(CDate(DateCom), "dd.mm.yyyy")
.Range("c13") = Format(Val(NmCom) + 910, "0")
.Range("g14") = Format(Val(NmCom), "0")
.Range("g7") = Client
Clt = Application.Match(.Range("g7"), WsFact.Columns(4), 0)
.Range("g6") = WsCl.Cells(Clt, 16)
.Range("g8") = WsCl.Cells(Clt, 6)
.Range("g9") = WsCl.Cells(Clt, 7) & " " & WsCl.Cells(Clt, 8)
.Range("c14") = WsCl.Cells(Clt, 14)
.Range("g11") = Representant
Rep = Application.Match(.Range("g11"), WsRep.Columns(2), 0)
.Range("g12") = WsRep.Cells(Rep, 5)
.Range("b10") = WsC.Range("x1").Value & " " & WsRep.Cells(Rep, 9)
.Range("b11") = WsC.Range("y1").Value & " " & WsRep.Cells(Rep, 11)
ar1 = WorksheetFunction.RoundDown(.Range("g46"), 1)
.Range("g46") = ar1
.Range("g47") = .Range("g45") + .Range("g46")
ar2 = WorksheetFunction.RoundDown(.Range("g47"), 1)
.Range("g47") = ar2
End With
End If
Next i
Set cel = plage.FindNext(cel)
Loop While Not cel Is Nothing And cel.Address <> premaddress
End If
End With