Bonjour,
Je débute en macro, merci de donc pour votre compréhension et pour votre aide.
Mon cas est le listing par produit de ventes, contenant le prix et la quantité.
Donc de la forme:
Product Id / Price / Qty
----------------------------------
Prod01 2 3
Prod01 3 2
Prod01 2 5
Prod02 3 2
Prod02 3 1
Mon objectif est de sommer les quantités des produits ayant été vendus au même prix.
Donc de la forme:
Product Id / Price / Qty
----------------------------------
Prod01 2 8
Prod01 3 2
Prod02 3 3
J'ai donc pensé à trier, puis faire des sous totaux sur la colonne 3 avec comme clé la colonne 2.
Le tri donne donc:
Product Id / Price / Qty
----------------------------------
Prod01 2 3
Prod01 2 5
Prod01 3 2
Prod02 3 2
Prod02 3 1
""""""""""" mon code de tri
SortRecord Macro
'
'
Cells.Select
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("A2:A8"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("B2:B8"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
.SetRange Range("A1:C8")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
""""""""""
Mais mon sous total sur la colonne ajoute la ligne 3 et 4 qui correspondent à 2 produits différents et je ne vois pas comment les différencier.
"""""""""""" mon code de sous totaux
Selection.SubTotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3), Replace:=True, _
PageBreaks:=False, SummaryBelowData:=True
"""""""""""""""""""""""""""""""
Merci pour vos idées,
Rem
Je débute en macro, merci de donc pour votre compréhension et pour votre aide.
Mon cas est le listing par produit de ventes, contenant le prix et la quantité.
Donc de la forme:
Product Id / Price / Qty
----------------------------------
Prod01 2 3
Prod01 3 2
Prod01 2 5
Prod02 3 2
Prod02 3 1
Mon objectif est de sommer les quantités des produits ayant été vendus au même prix.
Donc de la forme:
Product Id / Price / Qty
----------------------------------
Prod01 2 8
Prod01 3 2
Prod02 3 3
J'ai donc pensé à trier, puis faire des sous totaux sur la colonne 3 avec comme clé la colonne 2.
Le tri donne donc:
Product Id / Price / Qty
----------------------------------
Prod01 2 3
Prod01 2 5
Prod01 3 2
Prod02 3 2
Prod02 3 1
""""""""""" mon code de tri
SortRecord Macro
'
'
Cells.Select
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("A2:A8"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("B2:B8"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
.SetRange Range("A1:C8")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
""""""""""
Mais mon sous total sur la colonne ajoute la ligne 3 et 4 qui correspondent à 2 produits différents et je ne vois pas comment les différencier.
"""""""""""" mon code de sous totaux
Selection.SubTotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3), Replace:=True, _
PageBreaks:=False, SummaryBelowData:=True
"""""""""""""""""""""""""""""""
Merci pour vos idées,
Rem