Erreur d'execution '-2147417848' pivotcache
Résolu
chaymaek
Messages postés
6
Statut
Membre
-
chaymaek Messages postés 6 Statut Membre -
chaymaek Messages postés 6 Statut Membre -
Bonjour,
J'ai une erreur sur l'objet pivotcache de createpivottable (ligne en gras)
Est ce quelqu'un saurait d'où vient le problème ?
Mon code sert à faire des modification sur le fichier de base brut et puis crée un TCD..
Je vous remercie d'avance pour votre aide
Cordialement,
CK
Sub MEPISO()
Application.ScreenUpdating = False
' AJOUTER NOUVELLE COLONNE ARTICLE
Worksheets(1).Select
Columns("K:K").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("K1").Value = "Article"
' DEFINIR LES PARAMETRES
Dim i As Integer
Dim LR As Long
LR = WorksheetFunction.CountA(Range("A:A"))
' REMPLIR COLONNE ARTICLE
For i = 2 To LR
Cells(i, 11) = Cells(i, 9) & Cells(i, 10)
Next i
' AJOUTER NOUVELLE COLONNE ORDERED ML
Worksheets(1).Select
Columns("R:R").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("R1").Value = "Ordered ML"
0
' REMPLIR COLONNE ORDERED ML
For i = 2 To LR
Cells(i, 18) = Cells(i, 17) * Cells(i, 16)
Next i
' AJOUTER NOUVELLE COLONNE CONCATENER
Worksheets(1).Select
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Value = "Concatener"
' REMPLIR COLONNE CONCATENER
For i = 2 To LR
Cells(i, 2) = Cells(i, 1) & Cells(i, 11) & Cells(i, 16)
Next i
' SUPPRIMER LES DOUBLONS
ActiveSheet.Range("A:BM").RemoveDuplicates Columns:=2, Header:=xlYes
' AJOUTER TCD
' DECLARATION DES PARAMETRES
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim SrcData As String
Dim pf As String
Dim pf_Name As String
' DATA SOURCE
SrcData = ActiveSheet.Name & "!" & Range("A1:BM30000").Address(ReferenceStyle:=xlR1C1)
' CREATION NOUVELLE FEUILLE
Set sht = Sheets.Add
sht.Name = "TCD"
' LOCALISATION TCD
StartPvt = sht.Name & "!" & sht.Range("A3").Address(ReferenceStyle:=xlR1C1)
' CREATION PIVOT CACHE
Set pvtCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SrcData)
' CREATION TCD A PARTIR DU PIVOT CACHE
Set pvt = pvtCache.CreatePivotTable(TableDestination:=StartPvt, TableName:="PivotTable1")
' AJOUTER CHAMPS LIGNE
pvt.PivotFields("Article").Orientation = xlRowField
' AJOUTER CHAMPS COLONNE
pvt.PivotFields("suppliername").Orientation = xlColumnField
' AJOUTER CHAMPS VALEUR
pf = "Ordered ML"
pf_Name = "Somme Ordered"
pvt.AddDataField pvt.PivotFields("Ordered ML"), pf_Name, xlSum
' ENLEVER VIDE DES FILTRES
With Sheets("TCD").PivotTables("PivotTable1").PivotFields("Suppliername")
.PivotItems("(blank)").Visible = False
End With
End Sub
J'ai une erreur sur l'objet pivotcache de createpivottable (ligne en gras)
Est ce quelqu'un saurait d'où vient le problème ?
Mon code sert à faire des modification sur le fichier de base brut et puis crée un TCD..
Je vous remercie d'avance pour votre aide
Cordialement,
CK
Sub MEPISO()
Application.ScreenUpdating = False
' AJOUTER NOUVELLE COLONNE ARTICLE
Worksheets(1).Select
Columns("K:K").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("K1").Value = "Article"
' DEFINIR LES PARAMETRES
Dim i As Integer
Dim LR As Long
LR = WorksheetFunction.CountA(Range("A:A"))
' REMPLIR COLONNE ARTICLE
For i = 2 To LR
Cells(i, 11) = Cells(i, 9) & Cells(i, 10)
Next i
' AJOUTER NOUVELLE COLONNE ORDERED ML
Worksheets(1).Select
Columns("R:R").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("R1").Value = "Ordered ML"
0
' REMPLIR COLONNE ORDERED ML
For i = 2 To LR
Cells(i, 18) = Cells(i, 17) * Cells(i, 16)
Next i
' AJOUTER NOUVELLE COLONNE CONCATENER
Worksheets(1).Select
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Value = "Concatener"
' REMPLIR COLONNE CONCATENER
For i = 2 To LR
Cells(i, 2) = Cells(i, 1) & Cells(i, 11) & Cells(i, 16)
Next i
' SUPPRIMER LES DOUBLONS
ActiveSheet.Range("A:BM").RemoveDuplicates Columns:=2, Header:=xlYes
' AJOUTER TCD
' DECLARATION DES PARAMETRES
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim SrcData As String
Dim pf As String
Dim pf_Name As String
' DATA SOURCE
SrcData = ActiveSheet.Name & "!" & Range("A1:BM30000").Address(ReferenceStyle:=xlR1C1)
' CREATION NOUVELLE FEUILLE
Set sht = Sheets.Add
sht.Name = "TCD"
' LOCALISATION TCD
StartPvt = sht.Name & "!" & sht.Range("A3").Address(ReferenceStyle:=xlR1C1)
' CREATION PIVOT CACHE
Set pvtCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SrcData)
' CREATION TCD A PARTIR DU PIVOT CACHE
Set pvt = pvtCache.CreatePivotTable(TableDestination:=StartPvt, TableName:="PivotTable1")
' AJOUTER CHAMPS LIGNE
pvt.PivotFields("Article").Orientation = xlRowField
' AJOUTER CHAMPS COLONNE
pvt.PivotFields("suppliername").Orientation = xlColumnField
' AJOUTER CHAMPS VALEUR
pf = "Ordered ML"
pf_Name = "Somme Ordered"
pvt.AddDataField pvt.PivotFields("Ordered ML"), pf_Name, xlSum
' ENLEVER VIDE DES FILTRES
With Sheets("TCD").PivotTables("PivotTable1").PivotFields("Suppliername")
.PivotItems("(blank)").Visible = False
End With
End Sub
Configuration: Windows / Edge 18.17763
1 réponse
-
yg_be Messages postés 23437 Date d'inscription Statut Contributeur Dernière intervention Ambassadeur 1 588
bonjour, comme déjà demandé, peux-tu utiliser les balises de code?
peux-tu nous en dire plus: est-ce un nouveau code qui n'a jamais fonctionné?
moi je ferais:Dim StartPvt As range ' (...) set StartPvt = sht.[A3]