Re : comment faire un code VBA "évolutif" dont le nom de référence change (pour TDC)
ah oui j'oubliais.... En premier lieu j'avais fait le code ci bas que j'ai créé avec l'enregistreur de macro mais comme le nom de l'onglet change à chaque mois (ici c'est pour "avr")et le nom de la table (table3_5) je dois le changer manuellement dans le code... Dans le but d'automatiser le plus possible mes taches j'ai voulu tenté de modifier mon code... j'ai donc pensé qu'en pouvant prédire le nom de la table en utilisant un code qui nomme ma plage de mon tableau ("tableau(+1)") à chaque fois que la macros est exécuter ça serait peut-être bien mais je ne sais pas comment faire donc je compte sur votre expérience pour m'aider à trouver la solution à mon problème!
Sub totauxEtTDC()
Range("Table3_5[[#Headers],[Prix par item]]").Select
ActiveSheet.ListObjects("Table3").ShowTotals = True
Range("Table3_5[[#Totals],[Valeur total en CDN du produit]]").Select
ActiveSheet.ListObjects("Table3").ListColumns("Valeur total en CDN du produit") _
.TotalsCalculation = xlTotalsCalculationSum
Range("W1").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"avr!R1C1:R1048576C21", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="avr!R1C23", TableName:="PivotTable1", DefaultVersion:= _
xlPivotTableVersion12
Sheets("avr").Select
Cells(1, 23).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Projet")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Valeur total en CDN du produit"), _
"Count of Valeur total en CDN du produit", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of Valeur total en CDN du produit")
.NumberFormat = "# ##0,00 $"
End With
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
Range("X1").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of Valeur total en CDN du produit")
.Caption = "Sum of Valeur total en CDN du produit"
.Function = xlSum
End With
Range("W8").Select
End Sub
Merci
Bouclesdor