Re,
Une nouvelle proposition à étudier (Excel 2010+).
Cdlt.
Option Explicit
Public Sub Traitement_Donnees()
Dim wb As Workbook
Dim ws As Worksheet
Dim ptCache As PivotCache
Dim pt As PivotTable
Dim pf As PivotField
Dim modeCalc As XlCalculation
With Application
modeCalc = .Calculation
.Calculation = xlCalculationManual
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Données")
On Error Resume Next
wb.Worksheets("Données traitées").Delete
On Error GoTo 0
wb.Worksheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Données traitées"
Set ptCache = wb.PivotCaches.Create(xlDatabase, ws.ListObjects(1).Range, 4)
Set pt = ptCache.CreatePivotTable(Cells(1), "TCD_1", , 4)
With pt
.ManualUpdate = True
.AddFields _
RowFields:=Array("Département", "Type de camion", "Transporteur")
With .PivotFields("Prix")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Caption = "Prix "
End With
.InGridDropZones = True
.RowAxisLayout xlTabularRow
.RepeatAllLabels xlRepeatLabels
.TableStyle2 = ""
.DisplayContextTooltips = False
.ShowDrillIndicators = False
.ColumnGrand = False
.RowGrand = False
For Each pf In .PivotFields
pf.AutoSort xlAscending, pf.Name
pf.Subtotals(1) = True
pf.Subtotals(1) = False
Next pf
.ManualUpdate = False
.ManualUpdate = True
.AddDataField .PivotFields("Prix"), "rang", xlSum
With .PivotFields("rang")
.Caption = "rang "
.Calculation = xlRankAscending
.BaseField = "Transporteur"
End With
.ManualUpdate = False
.TableRange1.Offset(1, 0).Copy
Cells(8).PasteSpecial xlPasteValuesAndNumberFormats
End With
With ActiveSheet
.Columns("A:G").Delete
.Cells(1).CurrentRegion.Borders.Weight = xlThin
.[A1].Select
End With
With Application
.Calculation = modeCalc
.CutCopyMode = False
.EnableEvents = True
.ScreenUpdating = True
End With
ActiveWindow.DisplayGridlines = False
Set pt = Nothing
Set ptCache = Nothing
Set ws = Nothing
Set wb = Nothing
End Sub