1 2 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
Option Explicit
Option Base 0
Sub Couverture_Cde()
' Macro crée le 28/10/2010 par Bilbault Wilfried
'____________________________________________________________________________________________________________________________________
'----------------------------------------------------------------Déclaration des variables-------------------------------------------
Dim i As Integer, j As Long, Daterupture As Date, Stock As Variant, Codearticle As Variant, finListe As Long, x As Long
Dim dpt As Integer, z As Integer, NbreCde As Integer, finBes As Long, cpteur As Integer, y As Integer, t As Variant
Dim wsB As Worksheet, wsS As Worksheet, wsC As Worksheet
'Définit le tableau à 2 dimensions ainsi que leur taille.
Dim TabBesoin(0 To 65535, 1 To 4) As Variant
Set wsB = Sheets("Besoin")
Set wsS = Sheets("Total stock")
''-----------------------------------------------------------Mise en forme la liste des commandes-------------------------------------
''Tri des commandes par code puis date de libération
'Sheets("Ordre d'achat").Copy Before:=Sheets(2)
'
'Sheets("Ordre d'achat (2)").Name = "Analyse Commande"
Set wsC = Sheets("Analyse Commande")
finListe = wsC.Range("A65536").End(xlUp).Row
'dernier besoin
finBes = wsB.Range("A65536").End(xlUp).Row
x = 2
For x = 2 To finListe Step 1
Codearticle = 15 'wsC.Cells(x, 1)
NbreCde = WorksheetFunction.CountIf(wsC.Columns(1), Codearticle)
Erase TabBesoin
' Récupération du stock associé au code article commandé
Stock = WorksheetFunction.SumIf(wsS.Columns(1), Codearticle & "Stock-Accepté", wsS.Columns(3)) + _
WorksheetFunction.SumIf(wsS.Columns(1), Codearticle & "Stock-Quarantaine", wsS.Columns(3))
'----------------------------------------------------------------Calcul de la rupture-----------------------------------------------------------------------
' intégration du stock dans le tableau
TabBesoin(0, 3) = Stock
dpt = 1
i = 1
cpteur = 0
'intégration des commandes dans le tableau (partie à revoir car ne fonctionne pas avec plusieurs commandes)
For dpt = 1 To NbreCde
'date du commande
TabBesoin(i, 1) = wsC.Cells(x + cpteur, 5)
'quantité
TabBesoin(i, 2) = wsC.Cells(x + cpteur, 3)
i = i + 1
'intégration des besoins correspondants au code article commandé
For j = 2 To finBes
'conditions pour incrementer le tableau dimensionnelle
If wsB.Cells(j, 3) = Codearticle And wsB.Cells(j, 8) = "Ferme" And (wsB.Cells(j, 7) Like "M*") = False Then
'date du besoin
TabBesoin(i, 1) = wsB.Cells(j, 1)
'quantité
TabBesoin(i, 2) = wsB.Cells(j, 5) * -1
i = i + 1
End If
Next j
'boucle de tri
For z = 1 To i Step 1
If TabBesoin(z, 1) > TabBesoin(z + 1, 1) Then
For y = 1 To 2
t = TabBesoin(z, y)
TabBesoin(z, y) = TabBesoin(z + 1, y)
TabBesoin(z + 1, y) = t
Next y
End If
Next z
'calcul stock projeté et affichage
For i = 1 To i
TabBesoin(i, 3) = WorksheetFunction.Round(TabBesoin(i - 1, 3) + TabBesoin(i, 2), 2)
Debug.Print TabBesoin(i - 1, 1), TabBesoin(i - 1, 2), TabBesoin(i - 1, 3)
Next i |
Partager