Dim t As Variant, i As Byte, y As Byte, z As Byte
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Worksheets("Commandes Stinson").Activate
With Sheets("Commandes Stinson")
If TextBox41 = "" Then
If MsgBox("ENTRER UNE DATE ?", vbYesNo + vbQuestion, "Avertissement : ajouter une date ?") = vbYes Then Exit Sub
MsgBox "IL FAUT ENTRER UNE DATE POUR CONTINER ?", vbExclamation, "ERREUR ... Rien ne sera ajouté"
Exit Sub
End If
Range("c1").Offset(400)).Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("c1").Select
ActiveCell.FormulaR1C1 = "Date et quantité commandée"
Selection.Merge
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.RowHeight = 68
Range(ActiveCell, ActiveCell.Offset(400)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.Offset(3, 0).Select
y = 1
For i = 1 To 20
If Controls("ComboBox" & i).ListIndex - 1 Then
.Cells(Controls("ComboBox" & i).ListIndex + 3, 3) = Controls("Textbox" & y).Value
y = y + 1
End If
Next i
End With
Range("c2").Select
ActiveCell.Value = TextBox41.Value
Range("c3").Value = ("INT # " & TextBox42.Value)
With Sheets("Matières premières").Select
Range("d:e").Select
With Selection
Selection.Insert Shift:=xlToRight
End With
Sheets("Commandes Stinson").Select
Range("C2:C3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Matières premières").Select
Range("D1").Select
ActiveSheet.Paste
Columns("D").EntireColumn.AutoFit
Range("D3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Besoin"
End With
With Sheets("Commandes Stinson").Select
Range("c4").Activate
Suite1:
If ActiveCell = "" And ActiveCell.Offset(0, -2) = "" Then
GoTo Trier
Else
If ActiveCell <> "" Then
maQuantité = ActiveCell.Value
monProduit = ActiveCell.Offset(0, -2).Value
ActiveCell.Offset(1, 0).Select
GoTo Quantité_matière
Else
ActiveCell.Offset(1, 0).Activate
End If
GoTo Suite1
End If
Quantité_matière:
With Sheets("Produits").Activate
Range("b1").Activate
Do Until ActiveCell = monProduit
ActiveCell.Offset(0, 1).Activate
Loop
ActiveCell.Offset(2, 0).Activate
maComposante = ActiveCell.Value
monBesoin = ActiveCell.Offset(0, 1).Value
Vérification_inventaire:
With Sheets("Matières Premières").Activate
Range("A4").Activate
Do Until ActiveCell = ""
Do Until ActiveCell = maComposante
If ActiveCell.Value = "" Then Exit Sub
ActiveCell.Offset(1, 0).Activate
Loop
If ActiveCell = maComposante Then
ActiveCell.Offset(0, 3).Value = ActiveCell.Offset(0, 3) + (monBesoin * maQuantité)
With Sheets("Produits").Activate
If ActiveCell.Value = "" Then
GoTo Suite
Else
ActiveCell.Offset(1, 0).Activate
If ActiveCell <> "" Then
maComposante = ActiveCell.Value
monBesoin = ActiveCell.Offset(0, 1)
Else
Worksheets("Commandes Stinson").Select
GoTo Suite1
End If
End If
End With
End If
GoTo Vérification_inventaire
Loop
End With
End With
End With
Suite:
With Sheets("Commandes Stinson").Select
If ActiveCell.Value <> "" Then
maComposante = ActiveCell.Value
ActiveCell.Offset(0, 1).Activate
monBesoin = ActiveCell.Value
Else
ActiveCell.Offset(1, 2).Activate
If ActiveCell = "" Then
ActiveCell.Offset(1, 0).Select
If ActiveCell.Offset(0, -2).Value = "" Then
End If
End If
Do Until ActiveCell = ""
monProduit = ActiveCell
ActiveCell.Offset(0, 2).Select
If ActiveCell = "" Then
Else
maQuantité = ActiveCell.Value
End If
Loop
End If
End With
Trier:
With Sheets("Matières Premières").Select
Range("E:E,G:G,I:I,K:K,M:M,O:O,Q:Q,S:S,U:U,W:W,Y:Y ,AA:AA").Delete
ActiveWorkbook.Worksheets("Matières Premières").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Matières Premières").Sort.SortFields.Add Key:=Range _
("d1:t1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Matières Premières").Sort
.SetRange Range("d1:t300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Range("E:E,F:F,G:G,H:H,I:I,J:J,K:K,L:L,M:M,N:N,O:O ,P:P,Q:Q,R:R,S:S,U:U,W:W,Y:Y").Insert
Range("E:E,G:G,I:I,K:K,M:M,O:O,Q:Q,S:S,W:W").Selec t
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=0"
Selection.FormatConditions(Selection.FormatConditi ons.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("E4").Select
ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-1]"
Selection.NumberFormat = "General"
Selection.Copy
Range(ActiveCell, ActiveCell.Offset(400)).Select
ActiveSheet.Paste
ActiveCell.Offset(-1, 0).Select
ActiveCell.FormulaR1C1 = "Reste"
ActiveCell.Offset(1, 2).Select
Range("e1").Select
For z = 1 To 20
Range(ActiveCell, ActiveCell.Offset(400)).Copy
ActiveCell.Offset(0, 2).Select
ActiveSheet.Paste
Next
Range("E4").Select
End With
'tri dates
Sheets("Commandes Stinson").Select
ActiveWorkbook.Worksheets("Commandes Stinson").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Commandes Stinson").Sort.SortFields.Add Key:=Range _
("C2:L2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Commandes Stinson").Sort
.SetRange Range("C1:L300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Columns("C:V").ColumnWidth = 20
'cadrage
'Range("C4:C138").
' on verra le cadrage plus tard ;-)
Range("Q:Z").Delete Shift:=xlToLeft
Range("C1").Select
Fin:
Unload Me
End Sub