Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
950 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  TCD à plage variable

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

TCD à plage variable

n°2143305
A Pure Mon​steR
Posté le 22-05-2012 à 14:02:41  profilanswer
 

Bonjour tout le monde ,  
Dans le cadre de mon entreprise , je suis chargé de développer une macro ayant pour but de réaliser un tableau de bord  automatiquement.  
Pour information le tableau de bord est basé sur une feuille de données brutes à lignes variables et colonnes fixes.Et une dizaine de TCD est à créer  
 
Ne m'y connaissant pas trop en VBA . Je me suis débrouiller comme j'ai pu jusqu'à maintenant. J'ai fait beaucoup de recherches avant de poster ici , j'ai vu la plupart des sujets concernant le même problème mais cela n'a pas résolu mon problème.  
 

Code :
  1. Sub Rapport()
  2. ' Détermination de la limite du tableau
  3. Dim limite As Integer
  4. limite = ([B2].End(xlDown).Row)
  5. Range("A1:A" & limite).Select
  6. Application.DisplayAlerts = False
  7. 'Mise en forme première page
  8. Dim CL As Range
  9. Application.ScreenUpdating = False
  10.     Range("A1" ).CurrentRegion.Select
  11.     Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  12.     Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  13.     With Selection.Borders(xlEdgeLeft)
  14.         .LineStyle = xlContinuous
  15.         .Weight = xlMedium
  16.         .ColorIndex = xlAutomatic
  17.     End With
  18.     With Selection.Borders(xlEdgeTop)
  19.         .LineStyle = xlContinuous
  20.         .Weight = xlMedium
  21.         .ColorIndex = xlAutomatic
  22.     End With
  23.     With Selection.Borders(xlEdgeBottom)
  24.         .LineStyle = xlContinuous
  25.         .Weight = xlMedium
  26.         .ColorIndex = xlAutomatic
  27.     End With
  28.     With Selection.Borders(xlEdgeRight)
  29.         .LineStyle = xlContinuous
  30.         .Weight = xlMedium
  31.         .ColorIndex = xlAutomatic
  32.     End With
  33.     With Selection.Borders(xlInsideVertical)
  34.         .LineStyle = xlContinuous
  35.         .Weight = xlThin
  36.         .ColorIndex = xlAutomatic
  37.     End With
  38.     With Selection.Borders(xlInsideHorizontal)
  39.         .LineStyle = xlContinuous
  40.         .Weight = xlThin
  41.         .ColorIndex = xlAutomatic
  42.     End With
  43.     Range("A1" ).Select
  44.     Range(Selection, Selection.End(xlToRight)).Select
  45.     Selection.Font.Bold = True
  46.     With Selection
  47.         .HorizontalAlignment = xlCenter
  48.         .VerticalAlignment = xlBottom
  49.         .WrapText = False
  50.         .Orientation = 0
  51.         .AddIndent = False
  52.         .IndentLevel = 0
  53.         .ShrinkToFit = False
  54.         .ReadingOrder = xlContext
  55.         .MergeCells = False
  56.     End With
  57.     With Selection.Interior
  58.         .ColorIndex = 4
  59.         .Pattern = xlSolid
  60.         .PatternColorIndex = xlAutomatic
  61.     End With
  62.     Cells.Font.Size = 8
  63.     Columns("A:A" ).Select
  64.     Columns("A:A" ).EntireColumn.AutoFit
  65.     Columns("B:B" ).Select
  66.     Selection.ColumnWidth = 16.29
  67.     Columns("D:D" ).Select
  68.     Columns("D:D" ).EntireColumn.AutoFit
  69.     Columns("E:E" ).Select
  70.     Columns("E:E" ).EntireColumn.AutoFit
  71.     Range("G1:G" & limite).Select
  72.    
  73.     Range("A1" ).Select
  74. Application.ScreenUpdating = True
  75. 'Renommage de la feuille récapitulative
  76. Worksheets("Feuil1" ).Name = "Tableau Récapitulatif"
  77. 'Création des feuilles additionelles
  78. Worksheets("Feuil2" ).Name = "Calculs occupation par TECH"
  79. Worksheets("Feuil3" ).Name = "Calculs occupation par CLIENT"
  80. Sheets.Add.Move After:=Sheets(Sheets.Count)
  81. Sheets(Sheets.Count).Name = "Répartition TECH par CLIENT"
  82. Sheets.Add.Move After:=Sheets(Sheets.Count)
  83. Sheets(Sheets.Count).Name = "Répartion TECH par TYPE PB"
  84.    
  85.     Sheets.Add
  86.    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
  87.         "Feuil1!R1C1:R963C14", Version:=xlPivotTableVersion10).CreatePivotTable _
  88.         TableDestination:="Feuil4!R3C1", TableName:="Tableau croisé dynamique1", _
  89.         DefaultVersion:=xlPivotTableVersion10
  90.     Sheets("Feuil4" ).Select
  91.     Cells(3, 1).Select
  92.     With ActiveSheet.PivotTables("Tableau croisé dynamique1" ).PivotFields( _
  93.         "Tps passée" )
  94.         .Orientation = xlRowField
  95.         .Position = 1
  96.     End With
  97.     ActiveSheet.PivotTables("Tableau croisé dynamique1" ).PivotFields("Tps passée" ). _
  98.         Orientation = xlHidden
  99.     With ActiveSheet.PivotTables("Tableau croisé dynamique1" ).PivotFields( _
  100.         "ID intervenant" )
  101.         .Orientation = xlRowField
  102.         .Position = 1
  103.     End With
  104.     With ActiveSheet.PivotTables("Tableau croisé dynamique1" ).PivotFields( _
  105.         "Tps passée" )
  106.         .Orientation = xlRowField
  107.         .Position = 2
  108.     End With
  109.     Range("B4" ).Select
  110.     With ActiveSheet.PivotTables("Tableau croisé dynamique1" ).PivotFields( _
  111.         "Tps passée" )
  112.         .Orientation = xlColumnField
  113.         .Position = 1
  114.     End With
  115.     Range("B3" ).Select
  116.     ActiveSheet.PivotTables("Tableau croisé dynamique1" ).AddDataField ActiveSheet. _
  117.         PivotTables("Tableau croisé dynamique1" ).PivotFields("Tps passée" ), _
  118.         "Nombre de Tps passée", xlCount
  119.     Range("C10" ).Select
  120. End Sub


 
L'erreur se situe sur :  

Code :
  1. ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
  2.         "Feuil1!R1C1:R963C14", Version:=xlPivotTableVersion10).CreatePivotTable _
  3.         TableDestination:="Feuil4!R3C1", TableName:="Tableau croisé dynamique1", _
  4.         DefaultVersion:=xlPivotTableVersion10

 
'Erreur d'execution '5' : Argurment ou appel de procédure incorrect.  
Et lorsque je n'ai pas cette erreur , j'ai l'erreur d’exécution 1004.
Deplus , l'exemple du dessus n'est pas pour une plage variable car après de multiples essais, j'ai voulu faire plus simple donc merci de m'indiquer aussi comment résoudre ce problème .  
 
Merci d'avance

mood
Publicité
Posté le 22-05-2012 à 14:02:41  profilanswer
 

n°2143675
A Pure Mon​steR
Posté le 25-05-2012 à 15:18:20  profilanswer
 

Code :
  1. Dim lrow        As Long
  2.     Dim xlrow       As String
  3.     lrow = ActiveSheet.UsedRange.Rows.Count
  4.     xlrow = lrow
  5.     Application.CommandBars("PivotTable" ).Visible = True
  6.     ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
  7.         "Tableau Récapitulatif!R1C1:R" & xlrow & "C16" ).CreatePivotTable TableDestination:="'Calculs occupation par CLIENT'!R1C1", _ TableName:="Pivot_Categ"


 
J'ai fait cette modification , mais maintenant j'ai une erreur 1004/


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  TCD à plage variable

 

Sujets relatifs
Page de taille variable pour un portfolio wordpressAfficher variable dans textarea
plusieur TCD sur le même formulaire access[Résolu] [KSH] Executer plusieurs commandes dans une variable
Macro TCDResource id2 : utiliser ce résultat comme variable
[PERL] problème avec variable de session PHPRécuperer plusieur $_POST dans une seul variable possible ??
Transfert de variable en URL[RESOLU] pb ajax, jquery, variable session
Plus de sujets relatifs à : TCD à plage variable


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR