Erreur sur une macro mais je ne comprend pas
Résolu
manautop
Messages postés
138
Date d'inscription
Statut
Membre
Dernière intervention
-
pijaku Messages postés 12263 Date d'inscription Statut Modérateur Dernière intervention -
pijaku Messages postés 12263 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour, je reviens vers vous parce que j ai un probleme sur une macro, j ai une errer et je ne sais pas pourquoi
voici donc la macro
Sub TDC()
'creer un tableau dynamique croise sur mesure
'definition des variables
Dim Num_col As Integer, Num_col2 As Integer, Num_col3 As Integer, Num_col4 As Integer, diff As Integer
'apparition des messages demandant de selectionner les bonnes plages (pour les 3 set suivant)
Set range1 = Application.InputBox("Select the title of the first variable !", "Sélection de cellules", Type:=8)
Set Range3 = Application.InputBox("Select the title of the second variable !", "Sélection de cellules", Type:=8)
Num_col = range1.Column
Set range2 = Application.InputBox("Select the first column to the right of the table touches the table (select the letter) !", "Sélection de cellules", Type:=8)
Num_col2 = range2.Column
diff = -(Num_col2 - Num_col)
Lettre_col = Left(range2.Address(0, 0), (range2.Column < 27) + 2)
Set Num_ligne = Application.InputBox("Select the square tdc !", "Sélection de cellules", Type:=8)
Num_ligne = Num_ligne.Row
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Range3.Column
diff = -((Num_col2 + 1) - Num_col3)
Lettre_col = Left(range2.Offset(0, 1).Address(0, 0), (range2.Offset(0, 1).Column < 27) + 2)
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Num_col2 + 1
Num_col4 = Num_col3 + 2
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C" & Num_col2 & ":R6000C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("Tableau croisé dynamique1").AddFields RowFields:=Range3, ColumnFields:=range1
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields(CStr(range1))
.Orientation = xlDataField
.Function = xlCount
End With
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
Columns(Lettre_col).ClearContents
Lettre_col = range2.Column
Columns(Lettre_col).ClearContents
End Sub
l erreur se trouve sur la ligne que j ai mis en gras (d apres excel) mais je ne vois pas si quelau un peut m aider
merci d avance
john
voici donc la macro
Sub TDC()
'creer un tableau dynamique croise sur mesure
'definition des variables
Dim Num_col As Integer, Num_col2 As Integer, Num_col3 As Integer, Num_col4 As Integer, diff As Integer
'apparition des messages demandant de selectionner les bonnes plages (pour les 3 set suivant)
Set range1 = Application.InputBox("Select the title of the first variable !", "Sélection de cellules", Type:=8)
Set Range3 = Application.InputBox("Select the title of the second variable !", "Sélection de cellules", Type:=8)
Num_col = range1.Column
Set range2 = Application.InputBox("Select the first column to the right of the table touches the table (select the letter) !", "Sélection de cellules", Type:=8)
Num_col2 = range2.Column
diff = -(Num_col2 - Num_col)
Lettre_col = Left(range2.Address(0, 0), (range2.Column < 27) + 2)
Set Num_ligne = Application.InputBox("Select the square tdc !", "Sélection de cellules", Type:=8)
Num_ligne = Num_ligne.Row
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Range3.Column
diff = -((Num_col2 + 1) - Num_col3)
Lettre_col = Left(range2.Offset(0, 1).Address(0, 0), (range2.Offset(0, 1).Column < 27) + 2)
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Num_col2 + 1
Num_col4 = Num_col3 + 2
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C" & Num_col2 & ":R6000C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("Tableau croisé dynamique1").AddFields RowFields:=Range3, ColumnFields:=range1
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields(CStr(range1))
.Orientation = xlDataField
.Function = xlCount
End With
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
Columns(Lettre_col).ClearContents
Lettre_col = range2.Column
Columns(Lettre_col).ClearContents
End Sub
l erreur se trouve sur la ligne que j ai mis en gras (d apres excel) mais je ne vois pas si quelau un peut m aider
merci d avance
john
A voir également:
- Erreur sur une macro mais je ne comprend pas
- Telecharger macro convertir chiffre en lettre excel - Télécharger - Tableur
- Jitbit macro recorder - Télécharger - Confidentialité
- Une erreur s'est produite instagram ✓ - Forum Instagram
- Erreur 0x80070643 - Accueil - Windows
- Erreur 4101 france tv - Forum Lecteurs et supports vidéo
6 réponses
essaie ça :
va dans C:\Program Files\Microsoft Office et regarde à quelle version correspond 97
puis dans DefaultVersion:=xlPivotTableVersion10 met le numéro de version à la place de 10
va dans C:\Program Files\Microsoft Office et regarde à quelle version correspond 97
puis dans DefaultVersion:=xlPivotTableVersion10 met le numéro de version à la place de 10
no dsl ca ne marche pas j'ai essaye 11 et 12 (y a les deux dans mon dossier) mais j avasi develope la macro pour autre chose avant et ca marche tres bien.
Meme la ca marche mais le probleme c est qu elle ne prend pas tout mon tableau et j arrive pas a voir pourquoi
je l ai juste adapte en changeant cette ligne
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "10000")
par
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
et la tout marche sauf qu il ne descent pas en bas de mon tableau d ou le fait que j ai change le chiffre
la macro originelle lol
Sub TDC()
'creer un tableau dynamique croise sur mesure
'definition des variables
Dim Num_col As Integer, Num_col2 As Integer, Num_col3 As Integer, Num_col4 As Integer, diff As Integer
'apparition des messages demandant de selectionner les bonnes plages (pour les 3 set suivant)
Set range1 = Application.InputBox("Select the title of the first variable !", "Sélection de cellules", Type:=8)
Set Range3 = Application.InputBox("Select the title of the second variable !", "Sélection de cellules", Type:=8)
Num_col = range1.Column
Set range2 = Application.InputBox("Select the first column to the right of the table touches the table (select the letter) !", "Sélection de cellules", Type:=8)
Num_col2 = range2.Column
diff = -(Num_col2 - Num_col)
Lettre_col = Left(range2.Address(0, 0), (range2.Column < 27) + 2)
Set Num_ligne = Application.InputBox("Select the square tdc !", "Sélection de cellules", Type:=8)
Num_ligne = Num_ligne.Row
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "10000")
End With
Num_col3 = Range3.Column
diff = -((Num_col2 + 1) - Num_col3)
Lettre_col = Left(range2.Offset(0, 1).Address(0, 0), (range2.Offset(0, 1).Column < 27) + 2)
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "10000")
End With
Num_col3 = Num_col2 + 1
Num_col4 = Num_col3 + 2
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C" & Num_col2 & ":R6000C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("Tableau croisé dynamique1").AddFields RowFields:=Range3, ColumnFields:=range1
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields(CStr(range1))
.Orientation = xlDataField
.Function = xlCount
End With
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
Columns(Lettre_col).ClearContents
Lettre_col = range2.Column
Columns(Lettre_col).ClearContents
End Sub
j'arrive pas a m expliquer ou ca foire
Meme la ca marche mais le probleme c est qu elle ne prend pas tout mon tableau et j arrive pas a voir pourquoi
je l ai juste adapte en changeant cette ligne
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "10000")
par
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
et la tout marche sauf qu il ne descent pas en bas de mon tableau d ou le fait que j ai change le chiffre
la macro originelle lol
Sub TDC()
'creer un tableau dynamique croise sur mesure
'definition des variables
Dim Num_col As Integer, Num_col2 As Integer, Num_col3 As Integer, Num_col4 As Integer, diff As Integer
'apparition des messages demandant de selectionner les bonnes plages (pour les 3 set suivant)
Set range1 = Application.InputBox("Select the title of the first variable !", "Sélection de cellules", Type:=8)
Set Range3 = Application.InputBox("Select the title of the second variable !", "Sélection de cellules", Type:=8)
Num_col = range1.Column
Set range2 = Application.InputBox("Select the first column to the right of the table touches the table (select the letter) !", "Sélection de cellules", Type:=8)
Num_col2 = range2.Column
diff = -(Num_col2 - Num_col)
Lettre_col = Left(range2.Address(0, 0), (range2.Column < 27) + 2)
Set Num_ligne = Application.InputBox("Select the square tdc !", "Sélection de cellules", Type:=8)
Num_ligne = Num_ligne.Row
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "10000")
End With
Num_col3 = Range3.Column
diff = -((Num_col2 + 1) - Num_col3)
Lettre_col = Left(range2.Offset(0, 1).Address(0, 0), (range2.Offset(0, 1).Column < 27) + 2)
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "10000")
End With
Num_col3 = Num_col2 + 1
Num_col4 = Num_col3 + 2
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C" & Num_col2 & ":R6000C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("Tableau croisé dynamique1").AddFields RowFields:=Range3, ColumnFields:=range1
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields(CStr(range1))
.Orientation = xlDataField
.Function = xlCount
End With
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
Columns(Lettre_col).ClearContents
Lettre_col = range2.Column
Columns(Lettre_col).ClearContents
End Sub
j'arrive pas a m expliquer ou ca foire
Salut,
Juste une idée, essaie de changer :
par :
Juste une idée, essaie de changer :
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "Sheet1!R1C" & Num_col2 & ":R6000C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
par :
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "Sheet1!R1C" & Num_col2 & ":R10000C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
effectiivement je vais plus loin
mais j'ai 22124 lignes, du coup je change 10000 par 22124 ??? les trois fois??
mais j'ai 22124 lignes, du coup je change 10000 par 22124 ??? les trois fois??
ha bha ouui c'est ca pourtant il m'avait semble essaye, j'ai du faire une erreur quelque part.
merci a tous
la solution, on sait jamais
Sub TDC()
'creer un tableau dynamique croise sur mesure
'definition des variables
Dim Num_col As Integer, Num_col2 As Integer, Num_col3 As Integer, Num_col4 As Integer, diff As Integer
'apparition des messages demandant de selectionner les bonnes plages (pour les 3 set suivant)
Set range1 = Application.InputBox("Select the title of the first variable !", "Sélection de cellules", Type:=8)
Set Range3 = Application.InputBox("Select the title of the second variable !", "Sélection de cellules", Type:=8)
Num_col = range1.Column
Set range2 = Application.InputBox("Select the first column to the right of the table touches the table (select the letter) !", "Sélection de cellules", Type:=8)
Num_col2 = range2.Column
diff = -(Num_col2 - Num_col)
Lettre_col = Left(range2.Address(0, 0), (range2.Column < 27) + 2)
Set Num_ligne = Application.InputBox("Select the square tdc !", "Sélection de cellules", Type:=8)
Num_ligne = Num_ligne.Row
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Range3.Column
diff = -((Num_col2 + 1) - Num_col3)
Lettre_col = Left(range2.Offset(0, 1).Address(0, 0), (range2.Offset(0, 1).Column < 27) + 2)
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Num_col2 + 1
Num_col4 = Num_col3 + 2
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C" & Num_col2 & ":R22124C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("Tableau croisé dynamique1").AddFields RowFields:=Range3, ColumnFields:=range1
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields(CStr(range1))
.Orientation = xlDataField
.Function = xlCount
End With
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
Columns(Lettre_col).ClearContents
Lettre_col = range2.Column
Columns(Lettre_col).ClearContents
End Sub
merci a tous
la solution, on sait jamais
Sub TDC()
'creer un tableau dynamique croise sur mesure
'definition des variables
Dim Num_col As Integer, Num_col2 As Integer, Num_col3 As Integer, Num_col4 As Integer, diff As Integer
'apparition des messages demandant de selectionner les bonnes plages (pour les 3 set suivant)
Set range1 = Application.InputBox("Select the title of the first variable !", "Sélection de cellules", Type:=8)
Set Range3 = Application.InputBox("Select the title of the second variable !", "Sélection de cellules", Type:=8)
Num_col = range1.Column
Set range2 = Application.InputBox("Select the first column to the right of the table touches the table (select the letter) !", "Sélection de cellules", Type:=8)
Num_col2 = range2.Column
diff = -(Num_col2 - Num_col)
Lettre_col = Left(range2.Address(0, 0), (range2.Column < 27) + 2)
Set Num_ligne = Application.InputBox("Select the square tdc !", "Sélection de cellules", Type:=8)
Num_ligne = Num_ligne.Row
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Range3.Column
diff = -((Num_col2 + 1) - Num_col3)
Lettre_col = Left(range2.Offset(0, 1).Address(0, 0), (range2.Offset(0, 1).Column < 27) + 2)
With Range(Lettre_col & "1")
.FormulaR1C1 = "=RC[" & diff & "]"
.AutoFill Destination:=Range(Lettre_col & "1 :" & Lettre_col & "22124")
End With
Num_col3 = Num_col2 + 1
Num_col4 = Num_col3 + 2
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C" & Num_col2 & ":R22124C" & Num_col3).CreatePivotTable TableDestination:="Sheet1!R" & Num_ligne & "C" & Num_col4, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("Tableau croisé dynamique1").AddFields RowFields:=Range3, ColumnFields:=range1
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields(CStr(range1))
.Orientation = xlDataField
.Function = xlCount
End With
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
Columns(Lettre_col).ClearContents
Lettre_col = range2.Column
Columns(Lettre_col).ClearContents
End Sub