J'ai un tableau sur lesquel je fais des sous-totaux (à chaque changement de
...Région...)
Pour chaque donnée saisie dans le tableau, je voudrais connaître combien
cela représente par rapport au sous-total auquel il est associé.
Exemple :
J'ai des ventes classées par région (Alsace, Normandie, Lorraine, Nord...)
Je fais un sous total qui me donne SommeAlsace, SommeNormandie...
Je voudrais connaïtre par exemple pour chaque vente en Alsace, ce qu'elle
représente (en %) par rapport au total Alsace, et ainsi de suite pour chaque
région.
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
jb
Solution Macro:
On affiche le % en colonne D
A B C D 1 Produit CA Région 2 Produit1 100 A 14,08% 3 Produit3 110 A 15,49% 4 Produit6 100 A 14,08% 5 710 Total A 6 Produit2 5 65 B 29,09% 7 Produit4 100 B 5,15% 8 Produit7 567 B 29,20% 9 1942 Total B
Sub essai() lig = Range("c1").End(xlDown).Row i = lig - 1 Do While i > 1 total = Cells(i, 2) mrégion = Cells(i - 1, 3) Do While Cells(i - 1, 3) = mrégion Cells(i - 1, 4) = Cells(i - 1, 2) / total Cells(i - 1, 4).NumberFormat = "0.00%" i = i - 1 Loop i = i - 1 Loop End Sub
JB
Solution Macro:
On affiche le % en colonne D
A B C D
1 Produit CA Région
2 Produit1 100 A 14,08%
3 Produit3 110 A 15,49%
4 Produit6 100 A 14,08%
5 710 Total A
6 Produit2 5 65 B 29,09%
7 Produit4 100 B 5,15%
8 Produit7 567 B 29,20%
9 1942 Total B
Sub essai()
lig = Range("c1").End(xlDown).Row
i = lig - 1
Do While i > 1
total = Cells(i, 2)
mrégion = Cells(i - 1, 3)
Do While Cells(i - 1, 3) = mrégion
Cells(i - 1, 4) = Cells(i - 1, 2) / total
Cells(i - 1, 4).NumberFormat = "0.00%"
i = i - 1
Loop
i = i - 1
Loop
End Sub
A B C D 1 Produit CA Région 2 Produit1 100 A 14,08% 3 Produit3 110 A 15,49% 4 Produit6 100 A 14,08% 5 710 Total A 6 Produit2 5 65 B 29,09% 7 Produit4 100 B 5,15% 8 Produit7 567 B 29,20% 9 1942 Total B
Sub essai() lig = Range("c1").End(xlDown).Row i = lig - 1 Do While i > 1 total = Cells(i, 2) mrégion = Cells(i - 1, 3) Do While Cells(i - 1, 3) = mrégion Cells(i - 1, 4) = Cells(i - 1, 2) / total Cells(i - 1, 4).NumberFormat = "0.00%" i = i - 1 Loop i = i - 1 Loop End Sub
JB
C15
Bonsoir Jb
Merci de cette réponse, mais cette fonction, comment je l'appelle pour qu'elle s'exécute en colonne D ?
Merci de ton aide
A+
C15 "jb" a écrit dans le message de news:
Solution Macro:
On affiche le % en colonne D
A B C D 1 Produit CA Région 2 Produit1 100 A 14,08% 3 Produit3 110 A 15,49% 4 Produit6 100 A 14,08% 5 710 Total A 6 Produit2 5 65 B 29,09% 7 Produit4 100 B 5,15% 8 Produit7 567 B 29,20% 9 1942 Total B
Sub essai() lig = Range("c1").End(xlDown).Row i = lig - 1 Do While i > 1 total = Cells(i, 2) mrégion = Cells(i - 1, 3) Do While Cells(i - 1, 3) = mrégion Cells(i - 1, 4) = Cells(i - 1, 2) / total Cells(i - 1, 4).NumberFormat = "0.00%" i = i - 1 Loop i = i - 1 Loop End Sub
JB
Bonsoir Jb
Merci de cette réponse, mais cette fonction, comment je l'appelle pour
qu'elle s'exécute en colonne D ?
Merci de ton aide
A+
C15
"jb" <boisgontier@hotmail.com> a écrit dans le message de news:
1130682745.053932.256850@g47g2000cwa.googlegroups.com...
Solution Macro:
On affiche le % en colonne D
A B C D
1 Produit CA Région
2 Produit1 100 A 14,08%
3 Produit3 110 A 15,49%
4 Produit6 100 A 14,08%
5 710 Total A
6 Produit2 5 65 B 29,09%
7 Produit4 100 B 5,15%
8 Produit7 567 B 29,20%
9 1942 Total B
Sub essai()
lig = Range("c1").End(xlDown).Row
i = lig - 1
Do While i > 1
total = Cells(i, 2)
mrégion = Cells(i - 1, 3)
Do While Cells(i - 1, 3) = mrégion
Cells(i - 1, 4) = Cells(i - 1, 2) / total
Cells(i - 1, 4).NumberFormat = "0.00%"
i = i - 1
Loop
i = i - 1
Loop
End Sub
Merci de cette réponse, mais cette fonction, comment je l'appelle pour qu'elle s'exécute en colonne D ?
Merci de ton aide
A+
C15 "jb" a écrit dans le message de news:
Solution Macro:
On affiche le % en colonne D
A B C D 1 Produit CA Région 2 Produit1 100 A 14,08% 3 Produit3 110 A 15,49% 4 Produit6 100 A 14,08% 5 710 Total A 6 Produit2 5 65 B 29,09% 7 Produit4 100 B 5,15% 8 Produit7 567 B 29,20% 9 1942 Total B
Sub essai() lig = Range("c1").End(xlDown).Row i = lig - 1 Do While i > 1 total = Cells(i, 2) mrégion = Cells(i - 1, 3) Do While Cells(i - 1, 3) = mrégion Cells(i - 1, 4) = Cells(i - 1, 2) / total Cells(i - 1, 4).NumberFormat = "0.00%" i = i - 1 Loop i = i - 1 Loop End Sub
JB
jb
Bonsoir,
Ce n'est pas une fonction mais une procédure VBA qu'il faut placer dans un module:
-Alt+F11 pour basculer en VBA -Insertion/Module -Copier/Coller du code
Pour exécuter, Outils/Macro/Macros/Exécuter
JB
Bonsoir,
Ce n'est pas une fonction mais une procédure VBA qu'il faut placer
dans un module:
-Alt+F11 pour basculer en VBA
-Insertion/Module
-Copier/Coller du code