1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Sub Répartition()
Dim f1 As Worksheet
Dim DerLig As Long, DerLig_Tab As Long
Application.ScreenUpdating = False
Set f1 = Sheets("Donnée")
f1.Range("J2:P10000").ClearContents
DerLig = f1.Range("A" & Rows.Count).End(xlUp).Row 'dernière ligne de la Bdd
f1.Range("A1:C" & DerLig).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("J1:L1"), Unique:=True 'extraction sans doublons des sites, villes et articles
DerLig_Tab = f1.Range("J" & Rows.Count).End(xlUp).Row 'dernière ligne du tableau filtré
Range("M2:M" & DerLig_Tab).FormulaR1C1 = "=SUMPRODUCT((R2C1:R" & DerLig & "C1=RC10)*(R2C2:R" & DerLig & "C2=RC11)*(R2C3:R" & DerLig & "C3=RC12),(R2C7:R" & DerLig & "C7))" 'Consommation
Range("N2:N" & DerLig_Tab).FormulaR1C1 = "=VLOOKUP(RC12,'contraintes '!C1:C3,2,0)" 'QTE PREV ACHAT
Range("O2:O" & DerLig_Tab).FormulaR1C1 = "=VLOOKUP(RC12,'contraintes '!C1:C3,3,0)" 'STOCK DETENU
Range("P2:P" & DerLig_Tab).FormulaR1C1 = "=RC[-2]+RC[-1]" 'Total = Qté Prev Achat + Stock
Range("Q2:Q" & DerLig_Tab).FormulaR1C1 = "=SUMIF(R2C12:R" & DerLig & "C12,RC12,R2C13:R" & DerLig & "C13)" 'Total consommation par article
Range("R2:R" & DerLig_Tab).FormulaR1C1 = "=IF(RC16=0,0,IF(RC17<=RC16,RC13,(RC[-2]*RC[-5])/RC[-1]))" 'répartition par quantité
Range("M2:R" & DerLig_Tab).Value = Range("M2:R" & DerLig_Tab).Value
Set f1 = Nothing
End Sub |
Partager