1 pièce(s) jointe(s)
Différence exécution macro Bouton / fonction
Bonsoir à tous,
J'utilise une macro sous excel 2013 dans un fonctionnement simple.
J'ai un fichier avec 3 onglets
- Base de donnée avec ma matière "brut"
- un onglet "référence" pour une listbox
- un onglet "résultat" dans lequel je veux afficher un graphique croisée dynamique en fonction d'un paramètre choisis
Ce paramètre à étudier est choisi dans un Userform, et permet de faire un graph croisé dynamique en fonction de 3 paramètre (dont 2 fixe) (nom pièce, date et le paramètre choisi)
Le code que j'utilise pour faire mon tableau est le suivant :
Code:
1 2 3 4
| Sub appelChoix()
' appel du Userform de choix du paramètre
choixstat.Show
End Sub |
et ce userform renvoie vers la macro
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| Sub stat()
Application.ScreenUpdating = False
'************* inititalisation**** ***
Application.DisplayAlerts = False
Sheets("resultat").Delete
Worksheets.Add
ActiveSheet.Name = "resultat"
Application.DisplayAlerts = True
'************* inititalisation*******
CreationTableau 1, 1, choixstat.ComboBox1.Value, 220, 5, "tableau", "Graphique 1"
'*********** renvoie vers la procedure creation tableau *********************
Worksheets(1).Select
Range("A1").Select
Worksheets("resultat").Select
ActiveWindow.Zoom = 160
ActiveWindow.SmallScroll ToRight:=2
ActiveWindow.SmallScroll Down:=6
ActiveWindow.ScrollRow = 6
Application.ScreenUpdating = True
Unload choixstat
End Sub
Sub CreationTableau(posLeft As Single, posTop As Single, donnee As String, _
LeftGraph As Single, TopGraph As Single, nom As String, graphique As String)
Dim PTCache As PivotCache
Dim PT As PivotTable
Sheets("BDD").Select
'----------------------------------------------------------------------------
Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion.Address)
Set PT = PTCache.CreatePivotTable _
(TableDestination:="resultat!R" & posTop & "C" & posLeft, _
TableName:="graph")
With PT
.PivotFields("date").Orientation = xlRowField
.PivotFields("Nom d'ordre").Orientation = xlPageField
.PivotFields(donnee).Orientation = xlDataField
End With
On Error Resume Next
With Worksheets("resultat").PivotTables("graph").PivotFields("Nombre de " & donnee)
.Function = xlAverage
End With
On Error Resume Next
With Worksheets("resultat").PivotTables("graph").PivotFields("Somme de " & donnee)
.Function = xlAverage
End With
Worksheets("resultat").Shapes.AddChart2(LeftGraph, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Worksheets("resultat").Range(Range("A1").Offset(0, posLeft - 1), Range("A1").Offset(0, posLeft).End(xlDown).End(xlDown))
'----------------------------------------------------------------------------
End Sub |
C'est la que se pose mon problème :
Si j'exécute mon processus à partir d'un Bouton (un bouton me fait "appelchoix") pour faire apparaître le userform de sélection, le graphique croisée dynamique bug, je ne peux pas filtrer en fonction de plusieurs paramètres. par contre si je change d'onglet et reviens sur mon graphique sa se "débloque" et peux exécuter mes actions.
Si j'exécute mon processus à partir du ruban : développer - macro - appelchoix, mon userform apparait tout pareil, mon graphique se créer et je peux filtrer ...
Est-ce un bug Excel ? ou une erreur de ma part ? y'a t-il moyen d'y faire quelque chose ?