Re,
Tu as parfaitement compris : on doit normaliser les données pour travailler (correctement) avec un TCD.
La normalisation des données a été effectuée avec une procédure VBA (macro).
Je mets les procédures avec des commentaires pour une (bonne) compréhension.
ALT F11 pour ouvrir l'éditeur VBE ; voir module Feuil1 (Consolidation et TCD)
Cdlt.
Option Explicit
'Déclarations variables niveau module
Dim lo As ListObject
'-----------------------------------------------------------------------------
Private Sub cmdNormaliser_Les_Données_Click()
'Déclarations variables niveau procédure
Dim rCell As Range
Dim ws As Worksheet
Dim tbl, arr()
Dim I As Long, J As Long, k As Long
'Optimisation procédure (gel affichage)
Application.ScreenUpdating = False
'RAZ tableau si données, en conservant les formules et la mise en forme
With Me.ListObjects(1)
If Not .DataBodyRange Is Nothing Then .DataBodyRange.Delete
'Initialisation variable (cellule) pour la copie
Set rCell = .InsertRowRange.Cells(1)
End With
'Initialisation feuille
Set ws = ActiveWorkbook.Worksheets("Données BO")
'Tableau des données à normaliser
tbl = ws.Cells(1).CurrentRegion.Value
'Création tableau normalisé (5 lignes * n colonnes)
For I = 2 To UBound(tbl, 1)
For J = 4 To UBound(tbl, 2)
If tbl(I, J) <> 0 Then
ReDim Preserve arr(5, k + 1)
arr(0, k) = tbl(I, 1)
arr(1, k) = tbl(I, 2)
arr(2, k) = tbl(I, 3)
arr(3, k) = tbl(1, J)
arr(4, k) = tbl(I, J)
k = k + 1
End If
Next J
Next I
'Restitution des données dans le tableau
'(n lignes x 5 colonnes)
rCell.Resize(UBound(arr, 2), 5).Value = Application.Transpose(arr)
'Largeur colonnes
Me.ListObjects(1).HeaderRowRange.EntireColumn.AutoFit
'Actualisation du TCD
Me.PivotTables(1).PivotCache.Refresh
'RAZ des variables
Erase arr
Set rCell = Nothing
Set ws = Nothing
End Sub
'-----------------------------------------------------------------------------
Private Sub cmdRaz_Click()
'Optimisation procédure (gel affichage)
Application.ScreenUpdating = False
'RAZ tableau si données, en conservant les formules et la mise en forme
With Me.ListObjects(1)
If Not .DataBodyRange Is Nothing Then .DataBodyRange.Delete
End With
'Actualisation du TCD
Me.PivotTables(1).PivotCache.Refresh
End Sub