Excel Downloads
Forum

Précédent   Excel Downloads Forums > Excel > Forum Excel


Réponse
 
LinkBack Outils de la discussion
Vieux 21/04/2008, 16h51   #1 (permalink)
XLDnaute Junior
 
Avatar de corate92
 
Date d'inscription: janvier 2008
Version Excel : Excel 2003 (PC)
Messages: 79
Exclamation Problème avec un TCD et macro

Bonjour à tous!

J'en appelle à votre aide sur ce qui concerne VBA car là je m'arrache les cheveux de la tête!

J'essaie via une macro de créer automatiquement un Tableau Croisé Dynamique, j'ai donc utilisé l'enregistreur, jusqu'ici pas de soucis.

MAIS (car il faut bien qu'il en est un!) une fenetre s'affiche et m'indique "erreur exécution 1004, erreur définie par application ou par l'objet"

La partie en gras/rouge ci dessous s'affiche en jaune

Code:
Sub bilan_via_TCD()
'
' bilan_via_TCD Macro
' Macro enregistrée le 21/04/2008 par Corate92
'

'
If ActiveSheet.Name = "FEBRUARY" Then
        Range("A16:U1000").Select
         ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "FEBRUARY!R16C1:R1000C21").CreatePivotTable TableDestination:= _
        "'[Projects Status - CRAs- year 2008 EN DEVELOPPEMENT.xls]BILAN_FEV08'!R2C1", _
        TableName:="Tableau croisé dynamique3", DefaultVersion:= _
        xlPivotTableVersion10         ActiveWorkbook.ShowPivotTableFieldList = True
         ActiveWindow.SmallScroll Down:=-21
           With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("COUNTRY" _
        )
        .Orientation = xlRowField
        .Position = 1
         End With
         With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("CRA")
        .Orientation = xlColumnField
        .Position = 1
         End With
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields("Center"), _
        "Nombre de Center", xlCount
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields( _
        "Number of days of visits current month"), _
        "Nombre de Number of days of visits current month", xlCount
       ActiveWorkbook.ShowPivotTableFieldList = False
       
ElseIf ActiveSheet.Name = "MARCH" Then
        Range("A16:U1000").Select
         ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "MARCH!R16C1:R1000C21").CreatePivotTable TableDestination:= _
        "'[Projects Status - CRAs- year 2008 EN DEVELOPPEMENT.xls]BILAN_MAR08'!R2C1", _
        TableName:="Tableau croisé dynamique3", DefaultVersion:= _
        xlPivotTableVersion10
         ActiveWorkbook.ShowPivotTableFieldList = True
         ActiveWindow.SmallScroll Down:=-21
            With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("COUNTRY" _
        )
        .Orientation = xlRowField
        .Position = 1
         End With
         With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("CRA")
        .Orientation = xlColumnField
        .Position = 1
         End With
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields("Center"), _
        "Nombre de Center", xlCount
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields( _
        "Number of days of visits current month"), _
        "Nombre de Number of days of visits current month", xlCount
       ActiveWorkbook.ShowPivotTableFieldList = False

ElseIf ActiveSheet.Name = "APRIL" Then
         Range("A16:U1000").Select
         ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "APRIL!R16C1:R1000C21").CreatePivotTable TableDestination:= _
        "'[Projects Status - CRAs- year 2008 EN DEVELOPPEMENT.xls]BILAN_APR08'!R2C1", _
        TableName:="Tableau croisé dynamique3", DefaultVersion:= _
        xlPivotTableVersion10
         ActiveWorkbook.ShowPivotTableFieldList = True
         ActiveWindow.SmallScroll Down:=-21
         With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("COUNTRY" _
        )
        .Orientation = xlRowField
        .Position = 1
         End With
         With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("CRA")
        .Orientation = xlColumnField
        .Position = 1
         End With
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields("Center"), _
        "Nombre de Center", xlCount
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields( _
        "Number of days of visits current month"), _
        "Nombre de Number of days of visits current month", xlCount
       ActiveWorkbook.ShowPivotTableFieldList = False
       
ElseIf ActiveSheet.Name = "MAY" Then
          Range("A16:U1000").Select
         ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "MAY!R16C1:R1000C21").CreatePivotTable TableDestination:= _
        "'[Projects Status - CRAs- year 2008 EN DEVELOPPEMENT.xls]BILAN_MAY08'!R2C1", _
        TableName:="Tableau croisé dynamique3", DefaultVersion:= _
        xlPivotTableVersion10
         ActiveWorkbook.ShowPivotTableFieldList = True
         ActiveWindow.SmallScroll Down:=-21
         With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("COUNTRY" _
        )
        .Orientation = xlRowField
        .Position = 1
         End With
         With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields("CRA")
        .Orientation = xlColumnField
        .Position = 1
         End With
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields("Center"), _
        "Nombre de Center", xlCount
         ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
        PivotTables("Tableau croisé dynamique3").PivotFields( _
        "Number of days of visits current month"), _
        "Nombre de Number of days of visits current month", xlCount
       ActiveWorkbook.ShowPivotTableFieldList = False
       
       End If
       
 End Sub
aie aie
Voyez vous de quoi il s'agit?
Je vous mets le fichier en PJ en espérant que cela puisse vous aider...

Merci beaucoup si quelqu'un m'aider...

Cora
Fichiers attachés
Type de fichier : xls TEST.xls (27,5 Ko, 2 affichages)
__________________
Petite Cora ....
corate92 est déconnecté   Réponse avec citation
ANNONCES
Vieux 21/04/2008, 17h36   #2 (permalink)
XLDnaute Occasionel
 
Date d'inscription: mars 2008
Messages: 130
Par défaut Re : Problème avec un TCD et macro

Salut a toi corate

Dommage que tu n'ai pas laissé ton code dans le fichier ca aurait été plus pratique pour faire des essais... J'ai eu le meme problème récemment, chez moi ca venait de la définition du range dans source_data. Je l'ai résolu en définissant une variable range que j'apelle ensuite.


exemple :
Code:
Dim rgetab As Range
'Le set du range est obligatoire
Set rgetab = USD.Range(USD.Cells(5, 1), USD.Cells(L, 72))
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        rgetab).CreatePivotTable TableDestination:="", TableName:= _
        "PivotTable3", DefaultVersion:=xlPivotTableVersion10
'comme tu le vois j'apelle directement mon range nommé ainsi. Et la je n'ai plus cette erreur 1004
Voilà, essaye ceci, si ca ne marche pas essaye de remettre ton code dans ton fichier et de nous l'envoyer...
A te lire
Pierwak est déconnecté   Réponse avec citation
Vieux 21/04/2008, 17h45   #3 (permalink)
XLDnaute Junior
 
Avatar de corate92
 
Date d'inscription: janvier 2008
Version Excel : Excel 2003 (PC)
Messages: 79
Par défaut Re : Problème avec un TCD et macro

Bonjour,

Merci de t'occcuper de ce souci!

avec ton code, j'ai un message d'erreur indiquant "Variable non définie" pour
USD.Range(USD.Cells(5, 1), USD.Cells(L, 72))

????
Que faire?
__________________
Petite Cora ....
corate92 est déconnecté   Réponse avec citation
ANNONCES
Réponse

Liens sociaux

Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui

Discussions similaires
Discussion Auteur Forum Réponses Dernier message
probleme avec une macro tactic6 Forum spécial EXCEL 2007 2 10/01/2008 20h22
Problème avec une macro. Cyril Forum Excel Downloads - Archives 41 18/10/2004 15h44
Probleme avec une macro Cédric Forum Excel Downloads - Archives 8 14/06/2004 12h51
Probleme de recherche (avec macro) pour alimenter un tableau avec des données dj.run Forum Excel Downloads - Archives 5 09/09/2003 19h02
probleme avec macro cool Forum Excel Downloads - Archives 2 20/03/2003 13h39


Fuseau horaire GMT +2. Il est actuellement 11h09.


(C) 2006 Excel Downloads