Bonjour à tous, à forum
Aujourd'hui je rencontre un problème. J'ai essayé de faire un boucle sur la création de tableau croisé dynamique dans la meme feuille. Si quelqu'un d'entre vous a le temps, merci à vous de me donner un coup de main à voir un erreur sur mon code:Je ne sais pas comment faire. Merci d'avance pour votre aide.
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
 
Sub CreerTCD()
Dim lig As Integer
Dim tcd As Worksheet
Dim tableau(2) As String
 
' effacer feuille macro
Set tcd = sheets("testTCD")
     .Select
     Cells.Select
     Selection.ClearContents
Rang("A1").Select
End With
 
'creation tableau croise 
tcd.Select
Cells(3,1)Select
 
lig=3
tableau = Array("a","b","c")
For i = LBound(tableau,1) To UBound(tableau,1)
        ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="TestMacro!R2C1:R18365C32", Version:=xlPivotTableVersion10).CreatePivotTable TableDestination:="TestTCD!R" & lig & "C1", TableName:= "TCD" & i, defaultVersion:= xlPivotTableVersion10
With ActiveSheet.PivotTables("TCD"& i )
        With .PivotFields("month")
                .Orientation = xlRowField
        End With
        With .PivotFields("year")
                .Orientation = xlColumnField
        End With
        With .PivotFields(tableau(i-1))
                .Orientation = xlDataField
                .Function = xlSum
                 .NumberFormat = "#,#0"
        End With
lig = ActiveSheet.Cells.Find("*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row+5
Range("A" & lig).Select
Next i       
End Sub