Bonsoir,
Je te propose une solution, mais il faut que tu crées ton classeur de macros personnelles.
La première question est : sais-tu de quoi je parle?
Quand ton classeur PERSONAL.XLSB est crée, tu copies cette procédure dans un nouveau module :
Option Explicit
'Option Private Module
Public Sub Traitement_Importation()
Dim wb As Workbook
Dim wsData As Worksheet, wsPT As Worksheet
Dim lastCol As Long, lastRow As Long
Dim lo As ListObject
Dim ptCache As PivotCache
Dim pt As PivotTable
Dim CalcMode As XlCalculation
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Set wb = ActiveWorkbook
Set wsData = wb.Worksheets(1)
With wsData
lastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
Set lo = wsData.ListObjects.Add(xlSrcRange, .Cells(1).Resize(lastRow, lastCol), , xlNo)
With lo
.Name = "tblImportation"
.TableStyle = "TableStyleLight8"
End With
End With
wb.Worksheets.Add After:=Worksheets(Worksheets.Count)
Set wsPT = ActiveSheet
ActiveSheet.Name = "TCD"
With wsPT
Set ptCache = wb.PivotCaches.Create(xlDatabase, lo.Range, 3)
Set pt = ptCache.CreatePivotTable(.Cells(1), "PT_1", , 3)
With pt
.ManualUpdate = True
With .PivotFields("Colonne2")
.Orientation = xlRowField
.Caption = "Date"
End With
With .PivotFields("Colonne7")
.Orientation = xlDataField
.Position = 1
.Function = xlSum
.NumberFormat = "#,##0"
.Caption = "Colonne7 "
End With
With .PivotFields("Colonne9")
.Orientation = xlDataField
.Position = 2
.Function = xlSum
.NumberFormat = "#,##0"
.Caption = "Colonne9 "
End With
.RowAxisLayout xlTabularRow
.TableStyle2 = "PivotStyleMedium2"
.ManualUpdate = False
End With
End With
Application.Calculation = CalcMode
Set pt = Nothing
Set ptCache = Nothing
Set lo = Nothing
Set wsPT = Nothing: Set wsData = Nothing
Set wb = Nothing
End Sub
Ensuite, tu vas ajouter une commande personnalisée dans la barre d'outils Accès rapide (Options avancées d'Excel).
https://support.office.com/fr-be/article/Personnaliser-la-barre-doutils-Acc%C3%A8s-rapide-6c616455-653c-451c-93f7-96082e98de4d?ui=fr-FR&rs=fr-BE&ad=BE
Tu vas certainement chercher un peu, mais tu dois trouver PERSONAL.XLSB!Traitement_Importation.
Tu l'ajoutes à la barre d'outils Accès rapide [pour tous les documents (par défaut)].
Tu enregistres le tout et tu quittes Excel.
Pour tester, tu ouvres un de tes fichiers d'importation (brut) SAP et tu lances la procédure à partir de la barre d'outils Accès rapide.
Bon si ce n'est pas clair, tu me redis.
Cdlt.