Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/10/2011, 00h54   #1
Invité de passage
 
Homme
Inscription : octobre 2011
Messages : 1
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : octobre 2011
Messages : 1
Points : 2
Points : 2
Par défaut créer un TCD qui s'actualise avec une macro

bonsoir je veux créer un TCD en excécutant une macro mais ca crée erreur...
aider moi merci...

Code :
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
Sub TCD_vente()
'
' TCD_vente Macro
'
 
'
    Range("A5:M199").Select
    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "BASE DE DONNEES!R5C1:R199C13", Version:=xlPivotTableVersion12). _
        CreatePivotTable TableDestination:="Feuil2!R3C1", TableName:= _
        "Tableau croisé dynamique4", DefaultVersion:=xlPivotTableVersion12
    Sheets("Feuil2").Select
    Cells(3, 1).Select
    With feuille2.PivotTables("Tableau croisé dynamique4")
        .InGridDropZones = True
        .RowAxisLayout xlTabularRow
    End With
    With feuille2.PivotTables("Tableau croisé dynamique4").PivotFields( _
        "articles")
        .Orientation = xlRowField
        .Position = 1
    End With
    feuille2.PivotTables("Tableau croisé dynamique4").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique4").PivotFields("Qté vendue"), _
        "Somme de Qté vendue", xlSum
    feuille2.PivotTables("Tableau croisé dynamique4").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique4").PivotFields("Prix de vente"), _
        "Somme de Prix de vente", xlSum
    feuille2.PivotTables("Tableau croisé dynamique4").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique4").PivotFields("Montant"), _
        "Somme de Montant", xlSum
    Range("C4").Select
    With feuille2.PivotTables("Tableau croisé dynamique4").PivotFields( _
        "Somme de Prix de vente")
        .Orientation = xlRowField
        .Position = 2
    End With
    feuille2.PivotTables("Tableau croisé dynamique4").PivotSelect _
        "articles[All;Total]", xlDataAndLabel, True
    Range("A3").Select
    With feuille2.PivotTables("Tableau croisé dynamique4").PivotFields( _
        "date de vente")
        .Orientation = xlPageField
        .Position = 1
    End With
    With feuille2.PivotTables("Tableau croisé dynamique4").PivotFields( _
        "Type de  vente")
        .Orientation = xlPageField
        .Position = 1
    End With
    With feuille2.PivotTables("Tableau croisé dynamique4").PivotFields("EQUIPE")
        .Orientation = xlPageField
        .Position = 2
    End With
End Sub
coorigé svp ce quie ne va pas merci
skophile est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/10/2011, 12h56   #2
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 037
Points : 4 037
Bonjour,

Sur quelle ligne as-tu l'erreur ? si tu cliques sur "débogage", la ligne est surlignée en jaune. Et comme te l'as demandé kiki29, quel est le message d'erreur ?

Et que représente "feuille2" une variable ou un codename ?
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/10/2011, 13h31   #3
Membre habitué
 
Philo
Inscription : février 2011
Messages : 80
Détails du profil
Informations personnelles :
Nom : Philo

Informations forums :
Inscription : février 2011
Messages : 80
Points : 117
Points : 117
Bonjour
Tu peux tester cela:

Code :
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
 
Sub TCD_vente()
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("TCD").Delete
Application.DisplayAlerts = True
 
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="BASE DE DONNEES!R5C1:R199C13"). _
        CreatePivotTable TableDestination:="", _
        TableName:="Tcd"
    ActiveSheet.Name = "TCD"
 
 
    With ActiveSheet.PivotTables("TCD")
        .InGridDropZones = True
        .RowAxisLayout xlTabularRow
    End With
    With ActiveSheet.PivotTables("Tcd").PivotFields( _
        "articles")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("Tcd").AddDataField ActiveSheet. _
        PivotTables("Tcd").PivotFields("Qté vendue"), _
        "Somme de Qté vendue", xlSum
    ActiveSheet.PivotTables("Tcd").AddDataField ActiveSheet. _
        PivotTables("Tcd").PivotFields("Prix de vente"), _
        "Somme de Prix de vente", xlSum
    ActiveSheet.PivotTables("Tcd").AddDataField ActiveSheet. _
        PivotTables("Tcd").PivotFields("Montant"), _
        "Somme de Montant", xlSum
    Range("C4").Select
    With ActiveSheet.PivotTables("Tcd").PivotFields( _
        "Somme de Prix de vente")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("Tcd").PivotSelect _
        "articles[All;Total]", xlDataAndLabel, True
    Range("A3").Select
    With ActiveSheet.PivotTables("Tcd").PivotFields( _
        "date de vente")
        .Orientation = xlPageField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("Tcd").PivotFields( _
        "Type de  vente")
        .Orientation = xlPageField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("Tcd").PivotFields("EQUIPE")
        .Orientation = xlPageField
        .Position = 2
    End With
End Sub
Je crois bien qu'elle pourrait etre simplifié!!
philo6 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/10/2011, 14h15   #4
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 037
Points : 4 037
@ philo6 :

La méthode "PivotCaches.Create" est disponible seulement depuis XL2007. Elle a remplacé "PivotCaches.Add". Comme c'est celle qu'emploie skophile, on peut supposer qu'il dispose de cette version (ou d''une version postérieure).
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 09h56.


 
 
 
 
Partenaires

Hébergement Web