IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Selection de certaines valeurs d'un champ TCD entre fonctionne sur VBA 2007/2003 et non sur VBA 2010


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    controleur de gestion
    Inscrit en
    Janvier 2013
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : controleur de gestion

    Informations forums :
    Inscription : Janvier 2013
    Messages : 81
    Points : 39
    Points
    39
    Par défaut Selection de certaines valeurs d'un champ TCD entre fonctionne sur VBA 2007/2003 et non sur VBA 2010
    Bonjour,

    J'ai créé un TCD sur VBA 2003 (qui fonctionne egalement sur VBA 2007). Mais lors du code de la condition (sélection) de valeurs sur un champ de tableau croisé dynamique, il y a une erreur "incompatibilité de type" lors de l'execution de la macro sur VBA 2010 (ligne code 131 et 132). J'ai joint le code ci-dessous.

    Pourriez vous me dire, SVP, pourquoi cette partie de code ne fonctionne pas sur VBA 2010 alors qu'il n'y a aucun probleme sur les versions 2007 et 2003 ?

    En vous remerciant.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    Sub FFonctionnement()
    '
     
    ' Macro enregistrée le 15/01/2013 par b276573
    '
     
    '
        'Sheets("intéresst").Select
        'ActiveWindow.SelectedSheets.Visible = False
        'And sht.Name <> "nom onglet" à ajouter si on veut laisser un autre onglet egalement
     
       Dim sht As Object
       For Each sht In ActiveWorkbook.Worksheets
       If sht.Name <> "Extraction H - frais fonct" Then sht.Visible = False
       Next sht
       Application.DisplayAlerts = False
       Worksheets("Extraction H - frais fonct").Name = "Base"
     
     
        Worksheets("Base").Activate
        ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
            "'Base'!R1C1:R65000C22").CreatePivotTable TableDestination:="", TableName:= _
            "Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
        ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
        ActiveSheet.Cells(3, 1).Select
        ActiveSheet.PivotTables("Tableau croisé dynamique1").AddFields RowFields:= _
            Array("Service Herakles", "centre de frais", "Données")
     
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields( _
            "Solde Réalise 2012")
            .Orientation = xlDataField
            .Caption = "Réalisé 2012"
            .Position = 1
            .Function = xlSum
            .NumberFormat = "#,##0"
        End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields( _
            "Solde Réalisé")
            .Orientation = xlDataField
            .Caption = "Réalisé 2013"
            .Position = 2
            .Function = xlSum
            .NumberFormat = "#,##0"
        End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields( _
            "ENGAGE")
            .Orientation = xlDataField
            .Caption = "Engagé"
            .Position = 3
            .Function = xlSum
            .NumberFormat = "#,##0"
        End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Actu3 2012")
            .Orientation = xlDataField
            .Caption = "Actu 2012"
            .Position = 4
            .Function = xlSum
            .NumberFormat = "#,##0"
        End With
           With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Notif 2013")
            .Orientation = xlDataField
            .Caption = " Budget 2013"
            .Position = 5
            .Function = xlSum
            .NumberFormat = "#,##0"
        End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").DataPivotField
            .Orientation = xlColumnField
            .Position = 1
        End With
     
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Etablissement"): .Orientation = xlPageField: .Position = 1: End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Secteur Herakles"): .Orientation = xlPageField: .Position = 2: End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("poste"): .Orientation = xlPageField: .Position = 3: End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("lib poste"): .Orientation = xlPageField: .Position = 4: End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Sous-section / Centre de frais"): .Orientation = xlPageField: .Position = 5: End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Type de poste"): .Orientation = xlPageField: .Position = 6: End With
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("direction Herakles"): .Orientation = xlPageField: .Position = 7: End With
     
        ActiveWorkbook.ShowPivotTableFieldList = False
     
        ActiveWorkbook.ShowPivotTableFieldList = True
        ActiveWorkbook.ShowPivotTableFieldList = False
        Columns("H:H").ColumnWidth = 20.14
        Rows("10:10").RowHeight = 27.75
        'Range("H10") = " Engagé N non " & Chr(10) & "soldé à date"
        'Range("H10").Select
        'With Selection
            '.HorizontalAlignment = xlGeneral
            '.VerticalAlignment = xlBottom
            '.WrapText = True
            '.Orientation = 0
            '.AddIndent = False
            '.IndentLevel = 0
            '.ShrinkToFit = False
            '.ReadingOrder = xlContext
            '.MergeCells = False
        'End With
        ActiveSheet.PivotTables("Tableau croisé dynamique1").CalculatedFields.Add _
            "Engagé + réel", "='Solde Réalisé' +'ENGAGE'", True
        ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Engagé + réel"). _
            Orientation = xlDataField
        ActiveSheet.PivotTables("Tableau croisé dynamique1").DisplayErrorString = True
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields( _
            "Somme de Engagé + réel")
            .NumberFormat = "#,##0"
        End With
        ActiveSheet.PivotTables("Tableau croisé dynamique1").DataPivotField.PivotItems( _
            "Somme de Engagé + réel").Caption = "Engagé + réalisé"
     
     
     
        ActiveSheet.PivotTables("Tableau croisé dynamique1").CalculatedFields.Add _
            "Avancement", "='Solde Réalisé' /'Notif 2013'", True
        ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Avancement"). _
            Orientation = xlDataField
        ActiveSheet.PivotTables("Tableau croisé dynamique1").DisplayErrorString = True
        Range("I12").Select
        With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields( _
            "Somme de Avancement")
            .NumberFormat = "0%"
        End With
        ActiveSheet.PivotTables("Tableau croisé dynamique1").DataPivotField.PivotItems( _
            "Somme de Avancement").Caption = "Avancement %"
     
        Columns("A:A").ColumnWidth = 35
     
        Dim AB As PivotItem
    For Each AB In ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Service Herakles").PivotItems
    If (AB.Name <> "(vide)") Then
    With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields( _
    "Service Herakles").PivotItems(AB.Name).Visible = True
    End With
    Else:
    With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields( _
    "Service Herakles")
    .PivotItems(AB.Name).Visible = False
    End With
    End If
    Next AB

    Cordialement.


    Yannick

  2. #2
    Expert éminent sénior

    Profil pro
    Conseil, Formation, Développement - Indépendant
    Inscrit en
    Février 2010
    Messages
    8 397
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Conseil, Formation, Développement - Indépendant

    Informations forums :
    Inscription : Février 2010
    Messages : 8 397
    Points : 16 225
    Points
    16 225
    Par défaut
    Bonjour

    AB.Name correspond-il à une colonne de dates ? A priori, non d'après ton code.

    Il y a des problèmes sur les vides et les dates depuis 2010 : est-ce le test sur vide ?
    Chris
    PowerQuery existe depuis plus de 13 ans, est totalement intégré à Excel 2016 &+. Utilisez-le !

    Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson.
    Confucius

    ----------------------------------------------------------------------------------------------
    En cas de résolution, n'hésitez pas cliquer sur c'est toujours apprécié...

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    controleur de gestion
    Inscrit en
    Janvier 2013
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : controleur de gestion

    Informations forums :
    Inscription : Janvier 2013
    Messages : 81
    Points : 39
    Points
    39
    Par défaut
    Bonjour,

    Merci pour votre réponse.

    AB est le.nom que j'ai utilisé pour éviter de récrire pivotitem plusieurs fois. AB.Name est la valeur du champ "service herakles". Ici cette valeur est "vide".

    Sinon très bonne remarque sur les "vides". En fouinant sur le net, j'ai vu que parfois VBA préfère le terme "blank" au lieu du "vide". Mais même en faisant cela, le même message d'erreur apparaît.

    Cordialement.

  4. #4
    Expert éminent sénior

    Profil pro
    Conseil, Formation, Développement - Indépendant
    Inscrit en
    Février 2010
    Messages
    8 397
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Conseil, Formation, Développement - Indépendant

    Informations forums :
    Inscription : Février 2010
    Messages : 8 397
    Points : 16 225
    Points
    16 225
    Chris
    PowerQuery existe depuis plus de 13 ans, est totalement intégré à Excel 2016 &+. Utilisez-le !

    Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson.
    Confucius

    ----------------------------------------------------------------------------------------------
    En cas de résolution, n'hésitez pas cliquer sur c'est toujours apprécié...

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    controleur de gestion
    Inscrit en
    Janvier 2013
    Messages
    81
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : controleur de gestion

    Informations forums :
    Inscription : Janvier 2013
    Messages : 81
    Points : 39
    Points
    39
    Par défaut
    Je te remercie. J'avais pas vu ce fil. Je vais essayer.d'adapter ta solution à mon cas. Mon niveau ne me permet pas trop de comprendre le pourquoi mais néanmoins mon code fonctionnera. C'est déjà bien.

    Merci bcp.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Utiliser valeur listbox pour champ TCD
    Par Scrabblouille dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 17/08/2011, 22h44
  2. Comment récuperer la valeur d'un champ select ?
    Par krikete13 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 28/05/2007, 01h29
  3. récuperer la valeur d'un champ select (liste déroulante)
    Par bous_saad317 dans le forum Struts 1
    Réponses: 7
    Dernier message: 03/11/2006, 13h14
  4. Réponses: 10
    Dernier message: 11/03/2006, 02h51
  5. Requete SELECT : prendre toutes les valeurs pour 1 champ
    Par fab22montpellier dans le forum Requêtes
    Réponses: 1
    Dernier message: 02/09/2005, 10h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo