Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

tableau croisé dynamique, macros

2 réponses
Avatar
xavier
Bonjour =E0 tous,
Les macro et ses myst=E8res....

J'ai un pb sur cette macro un petit peu incompr=E9hensible

Premier pb:
A la fin de la macro, j'aimerais faire un tableau crois=E9=20
dynamique. J'ai utilis=E9 une m=E9thode que je croyais rod=E9=20
(m=EAme technique dans une autre macro et aucun pb) avec=20
l'enreistreur de macro excel.
Et l=E0 quand le code s'ex=E9cute, excel me renvoie une erreur:

erreur d'ex=E9cution '9':
l'indice n'appartient pas =E0 la s=E9lection
et colorie la ligne en jaune:
ActiveChart.SetSourceData Source:=3DSheets("Feuil12").Range
("A3") dans le code source...

Pourquoi elle r=E2le la macro alors que la m=EAme technique=20
fonctionne pour une autre....

J'en perd mes petits rep=E8res en VBA.... :-((

J'esp=E8re que vous pourrez m'aider.

Ci-joint le code source.

Merci,

Xavier



Function NOSEM(D As Date) As Long
D =3D Int(D)
NOSEM =3D DateSerial(Year(D + (8 - Weekday(D)) Mod 7 -=20
3), 1, 1)
NOSEM =3D ((D - NOSEM - 3 + (Weekday(NOSEM) + 1) Mod 7))=20
\ 7 + 1
End Function

Sub Calcul()

Sheets("Bourogne Inbound").Activate
Dim rangee As Long

'Compl=E9ment des manquants
For rangee =3D 2 To Range("E65535").End(xlUp).Row
If Cells(rangee, 17) =3D "" Then
Cells(rangee, 17) =3D "=3DRC[-13]"
End If
Next

'Mise =E0 jour au format europ=E9en jour/mois/ann=E9e
Columns("Q:R").Select
Selection.NumberFormat =3D "m/d/yyyy"
=20
'nom des colonnes
'Cost center
Range("X1").Select
ActiveCell.FormulaR1C1 =3D "cost center"
Selection.Font.Bold =3D True
Selection.Interior.ColorIndex =3D 37

'weeks
Range("Y1").Select
ActiveCell.FormulaR1C1 =3D "Weeks"
Selection.Font.Bold =3D True
Selection.Interior.ColorIndex =3D 37
=20
'code buyers
Range("Z1").Select
ActiveCell.FormulaR1C1 =3D "code buyers"
Selection.Font.Bold =3D True
Selection.Interior.ColorIndex =3D 37
=20
'nom ligne
Range("AA1").Select
ActiveCell.FormulaR1C1 =3D "Ligne"
Selection.Font.Bold =3D True
Selection.Interior.ColorIndex =3D 37
=20


=20
'd=E9termination de la semaine, code buyers, ligne

For rangee =3D 2 To Range("E65535").End(xlUp).Row
'N=B0 de la semaine
Cells(rangee, 25).FormulaR1C1 =3D "=3DNOSEM(RC[-8])"
'Code buyers
Cells(rangee, 26).FormulaR1C1 =3D "=3DRIGHT(LEFT(RC[-
24],6),2)"
=20
Next rangee


'copier-coller de la cellule code buyer pour r=E9cup=E9rer que=20
les valeur et non les formules
Columns("Y:Y").Select
Selection.Copy
Columns("Y:Y").Select
Selection.PasteSpecial Paste:=3DxlValues,=20
Operation:=3DxlNone, SkipBlanks:=3D _
False, Transpose:=3DFalse
=20
Columns("Z:Z").Select
Selection.Copy
Columns("Z:Z").Select
Selection.PasteSpecial Paste:=3DxlValues,=20
Operation:=3DxlNone, SkipBlanks:=3D _
False, Transpose:=3DFalse
=20
'recherche de la ligne en fonction du code buyer

For rangee =3D 2 To Range("E65535").End(xlUp).Row
Select Case Cells(rangee, 26)
Case "11", "30", "51", "53"
Cells(rangee, 27) =3D "PPB"
Case "13", "14", "16", "34", "35", "93"
Cells(rangee, 27) =3D "PPR"
Case "15", "31", "54", "56", "62", "95", "96"
Cells(rangee, 27) =3D "PPS"
Case "32", "52", "92"
Cells(rangee, 27) =3D "PPC"
Case Else
End Select
=20
Next rangee

'petit graphique
Application.CutCopyMode =3D False
ActiveWorkbook.PivotCaches.Add(SourceType:=3DxlDatabase,=20
SourceData:=3D _
"Bourogne Inbound!R1C1:R269C27").CreatePivotTable=20
TableDestination:=3D"", _
TableName:=3D"Tableau crois=E9 dynamique1"
ActiveSheet.PivotTableWizard=20
TableDestination:=3DActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("Tableau crois=E9=20
dynamique1").SmallGrid =3D False
Charts.Add
ActiveChart.SetSourceData Source:=3DSheets
("Feuil12").Range("A3")
ActiveChart.Location Where:=3DxlLocationAsNewSheet
With ActiveChart.PivotLayout.PivotFields("Cost")
.Orientation =3D xlDataField
.Position =3D 1
End With
With ActiveChart.PivotLayout.PivotFields("Ligne")
.Orientation =3D xlRowField
.Position =3D 1
End With
With ActiveChart.PivotLayout.PivotFields("Weeks")
.Orientation =3D xlRowField
.Position =3D 2
End With
With ActiveChart.PivotLayout.PivotFields("Ligne")
.PivotItems("(vide)").Visible =3D False
End With

=20
=20
MsgBox "op=E9ration termin=E9 avec succ=E8s ! Bonne fin de=20
journ=E9e..", 64, "Attention !"
End Sub
.

2 réponses

Avatar
boblebob
slt,

allez je tente :
-que contient ta cellule A3 de la Feuil2, cette valeur n'est-elle pas
incompatible avec le code ?
-ne manque-t-il pas un truc du style .value ?
(ActiveChart.SetSourceData Source:=Sheets("Feuil12").Range
("A3").Value)

bon courage
--
a+
bob

(enlever nospam00-)
"xavier" a écrit dans le message de news:
08e701c34132$a0bc2180$
Bonjour à tous,
Les macro et ses mystères....

J'ai un pb sur cette macro un petit peu incompréhensible

Premier pb:
A la fin de la macro, j'aimerais faire un tableau croisé
dynamique. J'ai utilisé une méthode que je croyais rodé
(même technique dans une autre macro et aucun pb) avec
l'enreistreur de macro excel.
Et là quand le code s'exécute, excel me renvoie une erreur:

erreur d'exécution '9':
l'indice n'appartient pas à la sélection
et colorie la ligne en jaune:
ActiveChart.SetSourceData Source:=Sheets("Feuil12").Range
("A3") dans le code source...

Pourquoi elle râle la macro alors que la même technique
fonctionne pour une autre....

J'en perd mes petits repères en VBA.... :-((

J'espère que vous pourrez m'aider.

Ci-joint le code source.

Merci,

Xavier



Function NOSEM(D As Date) As Long
D = Int(D)
NOSEM = DateSerial(Year(D + (8 - Weekday(D)) Mod 7 -
3), 1, 1)
NOSEM = ((D - NOSEM - 3 + (Weekday(NOSEM) + 1) Mod 7))
7 + 1
End Function

Sub Calcul()

Sheets("Bourogne Inbound").Activate
Dim rangee As Long

'Complément des manquants
For rangee = 2 To Range("E65535").End(xlUp).Row
If Cells(rangee, 17) = "" Then
Cells(rangee, 17) = "=RC[-13]"
End If
Next

'Mise à jour au format européen jour/mois/année
Columns("Q:R").Select
Selection.NumberFormat = "m/d/yyyy"

'nom des colonnes
'Cost center
Range("X1").Select
ActiveCell.FormulaR1C1 = "cost center"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37

'weeks
Range("Y1").Select
ActiveCell.FormulaR1C1 = "Weeks"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37

'code buyers
Range("Z1").Select
ActiveCell.FormulaR1C1 = "code buyers"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37

'nom ligne
Range("AA1").Select
ActiveCell.FormulaR1C1 = "Ligne"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37




'détermination de la semaine, code buyers, ligne

For rangee = 2 To Range("E65535").End(xlUp).Row
'N° de la semaine
Cells(rangee, 25).FormulaR1C1 = "=NOSEM(RC[-8])"
'Code buyers
Cells(rangee, 26).FormulaR1C1 = "=RIGHT(LEFT(RC[-
24],6),2)"

Next rangee


'copier-coller de la cellule code buyer pour récupérer que
les valeur et non les formules
Columns("Y:Y").Select
Selection.Copy
Columns("Y:Y").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:úlse

Columns("Z:Z").Select
Selection.Copy
Columns("Z:Z").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:úlse

'recherche de la ligne en fonction du code buyer

For rangee = 2 To Range("E65535").End(xlUp).Row
Select Case Cells(rangee, 26)
Case "11", "30", "51", "53"
Cells(rangee, 27) = "PPB"
Case "13", "14", "16", "34", "35", "93"
Cells(rangee, 27) = "PPR"
Case "15", "31", "54", "56", "62", "95", "96"
Cells(rangee, 27) = "PPS"
Case "32", "52", "92"
Cells(rangee, 27) = "PPC"
Case Else
End Select

Next rangee

'petit graphique
Application.CutCopyMode = False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:= _
"Bourogne Inbound!R1C1:R269C27").CreatePivotTable
TableDestination:="", _
TableName:="Tableau croisé dynamique1"
ActiveSheet.PivotTableWizard
TableDestination:¬tiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("Tableau croisé
dynamique1").SmallGrid = False
Charts.Add
ActiveChart.SetSourceData Source:=Sheets
("Feuil12").Range("A3")
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart.PivotLayout.PivotFields("Cost")
.Orientation = xlDataField
.Position = 1
End With
With ActiveChart.PivotLayout.PivotFields("Ligne")
.Orientation = xlRowField
.Position = 1
End With
With ActiveChart.PivotLayout.PivotFields("Weeks")
.Orientation = xlRowField
.Position = 2
End With
With ActiveChart.PivotLayout.PivotFields("Ligne")
.PivotItems("(vide)").Visible = False
End With



MsgBox "opération terminé avec succès ! Bonne fin de
journée..", 64, "Attention !"
End Sub
.
Avatar
xavier
Salut Boblebob,

Je sais le code est un peut étrange, mais il a été
réalisé avec l'enregistreur de macro et quand je créé un
tableau croisé dynamique avec cet outil il l'écrit comme
cela. Comme je te le disais ce code fonctionne dans une
autre macro parfaitement bien..

Donc malheureusement je ne sais que faire

merci

Xavier
-----Message d'origine-----
slt,

allez je tente :
-que contient ta cellule A3 de la Feuil2, cette valeur
n'est-elle pas

incompatible avec le code ?
-ne manque-t-il pas un truc du style .value ?
(ActiveChart.SetSourceData Source:=Sheets("Feuil12").Range
("A3").Value)

bon courage
--
a+
bob

(enlever nospam00-)
"xavier" a écrit dans le message
de news:

08e701c34132$a0bc2180$
Bonjour à tous,
Les macro et ses mystères....

J'ai un pb sur cette macro un petit peu incompréhensible

Premier pb:
A la fin de la macro, j'aimerais faire un tableau croisé
dynamique. J'ai utilisé une méthode que je croyais rodé
(même technique dans une autre macro et aucun pb) avec
l'enreistreur de macro excel.
Et là quand le code s'exécute, excel me renvoie une
erreur:


erreur d'exécution '9':
l'indice n'appartient pas à la sélection
et colorie la ligne en jaune:
ActiveChart.SetSourceData Source:=Sheets("Feuil12").Range
("A3") dans le code source...

Pourquoi elle râle la macro alors que la même technique
fonctionne pour une autre....

J'en perd mes petits repères en VBA.... :-((

J'espère que vous pourrez m'aider.

Ci-joint le code source.

Merci,

Xavier



Function NOSEM(D As Date) As Long
D = Int(D)
NOSEM = DateSerial(Year(D + (8 - Weekday(D)) Mod 7 -
3), 1, 1)
NOSEM = ((D - NOSEM - 3 + (Weekday(NOSEM) + 1) Mod 7))
7 + 1
End Function

Sub Calcul()

Sheets("Bourogne Inbound").Activate
Dim rangee As Long

'Complément des manquants
For rangee = 2 To Range("E65535").End(xlUp).Row
If Cells(rangee, 17) = "" Then
Cells(rangee, 17) = "=RC[-13]"
End If
Next

'Mise à jour au format européen jour/mois/année
Columns("Q:R").Select
Selection.NumberFormat = "m/d/yyyy"

'nom des colonnes
'Cost center
Range("X1").Select
ActiveCell.FormulaR1C1 = "cost center"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37

'weeks
Range("Y1").Select
ActiveCell.FormulaR1C1 = "Weeks"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37

'code buyers
Range("Z1").Select
ActiveCell.FormulaR1C1 = "code buyers"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37

'nom ligne
Range("AA1").Select
ActiveCell.FormulaR1C1 = "Ligne"
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 37




'détermination de la semaine, code buyers, ligne

For rangee = 2 To Range("E65535").End(xlUp).Row
'N° de la semaine
Cells(rangee, 25).FormulaR1C1 = "=NOSEM(RC[-8])"
'Code buyers
Cells(rangee, 26).FormulaR1C1 = "=RIGHT(LEFT(RC[-
24],6),2)"

Next rangee


'copier-coller de la cellule code buyer pour récupérer que
les valeur et non les formules
Columns("Y:Y").Select
Selection.Copy
Columns("Y:Y").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:úlse

Columns("Z:Z").Select
Selection.Copy
Columns("Z:Z").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:úlse

'recherche de la ligne en fonction du code buyer

For rangee = 2 To Range("E65535").End(xlUp).Row
Select Case Cells(rangee, 26)
Case "11", "30", "51", "53"
Cells(rangee, 27) = "PPB"
Case "13", "14", "16", "34", "35", "93"
Cells(rangee, 27) = "PPR"
Case "15", "31", "54", "56", "62", "95", "96"
Cells(rangee, 27) = "PPS"
Case "32", "52", "92"
Cells(rangee, 27) = "PPC"
Case Else
End Select

Next rangee

'petit graphique
Application.CutCopyMode = False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:= _
"Bourogne Inbound!R1C1:R269C27").CreatePivotTable
TableDestination:="", _
TableName:="Tableau croisé dynamique1"
ActiveSheet.PivotTableWizard
TableDestination:¬tiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("Tableau croisé
dynamique1").SmallGrid = False
Charts.Add
ActiveChart.SetSourceData Source:=Sheets
("Feuil12").Range("A3")
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart.PivotLayout.PivotFields("Cost")
.Orientation = xlDataField
.Position = 1
End With
With ActiveChart.PivotLayout.PivotFields("Ligne")
.Orientation = xlRowField
.Position = 1
End With
With ActiveChart.PivotLayout.PivotFields("Weeks")
.Orientation = xlRowField
.Position = 2
End With
With ActiveChart.PivotLayout.PivotFields("Ligne")
.PivotItems("(vide)").Visible = False
End With



MsgBox "opération terminé avec succès ! Bonne fin de
journée..", 64, "Attention !"
End Sub
..



.