Compatibilité EXCEL 2010 avec EXCEL 2007

mimiaqu

XLDnaute Nouveau
Bonjour a tous,

Grace à votre précieuse aide j'ai obtenu la macro qui permet de créer un TCD avec des calculs qui correspondant à la méthode Pareto, le programme marche bien sur EXCEL 2010 sauf que quand j'ai voulu transférer le fichier a mes collègues les macros ne fonctionnent plus, le problème est dû au code "xlPercentRunningTotal" qui permet de calculer le % du résultat cumulé qui n'existe pas dans excel 2007.

J'ai essayé de créer un élément calculé dans le TCD mais malheureusement ça ne marche pas :(

pourriez vous m'aider a résoudre ce problème SVP

Merci d'avance
 

Pièces jointes

  • TCD.xlsm
    184.8 KB · Affichages: 43
  • TCD.xlsm
    184.8 KB · Affichages: 48
  • TCD.xlsm
    184.8 KB · Affichages: 47

chris

XLDnaute Barbatruc
Re : Compatibilité EXCEL 2010 avec EXCEL 2007

Bonjour

Je n'ai pas regardé le code mais effectivement cela ne marche pas avant la version 2010

Ce qui est possible de faire c'est un cumul classique en valeur.
Ensuite on a le choix entre :
  • un filtre 10 premiers sur les 80% du haut
  • l'ajout des valeurs en % de la colonne, un tri et une mise en forme conditionnelle qui clore les lignes dont la somme ne dépasse pas 80%
Un fois ton choix effectué, on peut bine sûr automatiser.
 

mimiaqu

XLDnaute Nouveau
Re : Compatibilité EXCEL 2010 avec EXCEL 2007

Merci d'avoir pris le temps de répondre effectivement le deuxième choix me semble la plus adéquate, par contre pour l'automatisation je sais pas du tout comment faire.
Merci encore une fois
 

chris

XLDnaute Barbatruc
Re : Compatibilité EXCEL 2010 avec EXCEL 2007

Bonjour

Code:
   With Worksheets("tcd").PivotTables("Tableau croisé dynamique3").PivotFields("Nombre de tg_nat").DataRange
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=SOMME($C$5:$C5)<=0,8"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent5
            .TintAndShade = 0.599963377788629
        End With
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions(1).ScopeType = xlFieldsScope
    End With

A adapter :
  • selon nom du TCD
  • position du TCD (on peut rendre la cellule C5 variable éventuellement)
  • Mise en forme souhaitée
 

mimiaqu

XLDnaute Nouveau
Re : Compatibilité EXCEL 2010 avec EXCEL 2007

Bonjour Chris,

j'ai intégré la partie du code comme convenu mais me donne une erreur dans la partie coloré du code
pourquoi a votre avis?
MERCI d'avance

Code:
Option Explicit
Sub test()
Dim tcd As PivotTable
With Sheets("tcd")
    If .PivotTables.Count > 0 Then .PivotTables(1).TableRange2.Delete
    Set tcd = .PivotTableWizard(xlDatabase, Sheets("stat").Range("A1").CurrentRegion, .Range("A1"))
End With
With tcd
    .AddDataField .PivotFields("tg_nat"), "Occurences", xlCount
    .AddDataField .PivotFields("tg_nat"), "Nombre de tg_nat", xlCount
    .AddDataField .PivotFields("Q_compenser"), "Min de Q_compenser", xlMin
    With .PivotFields("tg_nat")
        .Orientation = xlRowField
        .Position = 1
    End With

    With .PivotFields("Nombre de tg_nat")
       [COLOR="#FF8C00"] .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=SOMME($C$5:$C5)<=0,8"[/COLOR]
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent5
            .TintAndShade = 0.599963377788629
        End With
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions(1).ScopeType = xlFieldsScope
    End With
    With .DataPivotField
        .Orientation = xlColumnField
        .Position = 1
    End With
    .PivotFields("tg_nat").AutoSort xlDescending, "Occurences", .PivotColumnAxis.PivotLines(1), 1
End With

End Sub
 

chris

XLDnaute Barbatruc
Re : Compatibilité EXCEL 2010 avec EXCEL 2007

Bonjour

La couleur n'est pas passée...

Edit : si je vois la balise.

Je l'ai fait en version 2010 mais le code de MFC ne doit ps être différent. Je vais essayer de tester sur une machine en 2007.
 
Dernière édition:

chris

XLDnaute Barbatruc
Re : Compatibilité EXCEL 2010 avec EXCEL 2007

Bonjour

Il y avait plusieurs erreurs :
  • la mise en forme était faite trop tôt car l'orientation des champs calculés étaient en colonnes et non en ligne
  • tu avais oublié DataRange
  • le champ concerné n'était pas au format %
  • le tableau n'est pas au même endroit (plus haut) : j'ai adapté la formule

Code:
Option Explicit
Sub test()
Dim tcd As PivotTable
With Sheets("tcd")
    If .PivotTables.Count > 0 Then .PivotTables(1).TableRange2.Delete
    Set tcd = .PivotTableWizard(xlDatabase, Sheets("stat").Range("A1").CurrentRegion, .Range("A1"))
End With
With tcd
    .AddDataField .PivotFields("tg_nat"), "Occurences", xlCount
    .AddDataField .PivotFields("tg_nat"), "Nombre de tg_nat", xlCount
        .PivotFields("Nombre de tg_nat").Calculation = xlPercentOfColumn
        .PivotFields("Nombre de tg_nat").NumberFormat = "0.00%"

    .AddDataField .PivotFields("Q_compenser"), "Min de Q_compenser", xlMin
    With .PivotFields("tg_nat")
        .Orientation = xlRowField
        .Position = 1
    End With

    With .DataPivotField
        .Orientation = xlColumnField
        .Position = 1
    End With
    With .PivotFields("Nombre de tg_nat").DataRange
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=SOMME($C$2:$C3)<=0,8"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent5
            .TintAndShade = 0.599963377788629
        End With
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions(1).ScopeType = xlFieldsScope
    End With
    .PivotFields("tg_nat").AutoSort xlDescending, "Occurences", .PivotColumnAxis.PivotLines(1), 1
End With

End Sub
 

chris

XLDnaute Barbatruc
Re : Compatibilité EXCEL 2010 avec EXCEL 2007

Re

Merci de ne pas utiliser les MP pour les questions techniques.

Tu peux ajouter une formule en dehors du TCD :
Code:
=SI(ET(A3<>"";A3<>"Total général");SOMME($C$3:C3);"")
 

Discussions similaires

Statistiques des forums

Discussions
312 545
Messages
2 089 480
Membres
104 178
dernier inscrit
Lampalator