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
| Function livraison_doc(ByRef cellules_quantite As Range, ByRef cellules_annee As Range, ByRef continue As Byte, ByRef quantite_liv As Byte) As Integer
Dim cellule_quantite As Range
Dim cellule_annee As Range
Dim nb_mois As Integer
Dim q_liv As Integer
Dim colonne_start As Integer
Dim colonne As Integer
For Each cellule_annee In cellules_annee
If colonne_start = 0 Then colonne_start = cellule_annee.Column - 1
colonne = cellule_annee.Column - colonne_start
If cellules_quantite.Cells(1, colonne) <> "" And cellules_annee.Cells(0, colonne) = Year(Cells(7, Selection.Column)) Then
nb_mois = Round(cellules_quantite.Cells(1, colonne) / quantite_liv, 0)
Select Case continue
Case 1
If Month(Cells(7, Selection.Column)) = 12 - nb_mois + 1 Then
q_liv = cellules_quantite.Cells(1, colonne) - quantite_liv * (nb_mois - 1)
livraison_doc = q_mun
ElseIf Month(Cells(7, Selection.Column)) > 12 - nb_mois + 1 Then
q_liv = quantite_liv
livraison_doc = q_liv
Else
livraison_doc = 0
End If
Exit Function
Case 2
If Month(Cells(7, Selection.Column)) = nb_mois Then
q_liv = cellules_quantite.Cells(1, colonne) - quantite_liv * (nb_mois - 1)
livraison_doc = q_liv
ElseIf Month(Cells(7, Selection.Column)) < nb_mois Then
q_liv = quantite_liv
livraison_doc = q_liv
Else
livraison_doc = 0
End If
Exit Function
End Select
End If
Next
End Function |
Partager