Filtre PivotTable

Résolu
rafou29 Messages postés 29 Date d'inscription lundi 8 mars 2010 Statut Membre Dernière intervention 14 avril 2010 - 1 avril 2010 à 08:57
rafou29 Messages postés 29 Date d'inscription lundi 8 mars 2010 Statut Membre Dernière intervention 14 avril 2010 - 1 avril 2010 à 16:16
Bonjour,

Quelqu'un pourrait-il me donner le code VB qui permet d'insérer la colonne de notre choix dans le "Filter Range" d'un PivotTable ?

A savoir que mon PivotTable se situe en "Sheet3", les données sont en "Sheet1" et je souhaiterais pouvoir filtrer les données que j'y insère en utilisant la colonne "Ligne" en G2 de ma "Sheet1".

Cela doit me permettre d'améliorer l'affichage de mon histogramme.

Voici mon code actuel :

Dim plage, maplage

Set plage = Sheets("Sheet1").Range("A1").CurrentRegion

Application.ScreenUpdating = False
Sheets("Sheet1").Activate
Set maplage = Range("A1").CurrentRegion
maplage.Name = "TCD"
Sheets("Sheet3").Activate

    With ActiveSheet
        .PivotTableWizard SourceType:=xlDatabase, SourceData:="TCD", TableDestination:="R1C1", TableName:="TCD1"
        .PivotTables("TCD1").SmallGrid = False
        .PivotTables("TCD1").AddFields RowFields:="Sc", ColumnFields:=Array("Arrêt")
        .PivotTables("TCD1").PivotFields("%").Orientation = xlDataField
    End With
    With Application
        .CommandBars("PivotTable").visible = False
        .ScreenUpdating = False
    End With

    Charts.Add
    ActiveChart.ChartType = xlColumnStacked
    ActiveChart.SetSourceData Source:=Sheets("Sheet3").Range("A3:E6"), PlotBy:= _
    xlColumns
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet3"
    ActiveChart.SeriesCollection(1).Select
    ActiveChart.ChartArea.Select
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Arrêt"
        .Axes(xlCategory, xlPrimary).HasTitle = False
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "%"
    End With
    ActiveChart.HasLegend = True
    ActiveChart.HasDataTable = False

    ActiveChart.Axes(xlCategory).Select
    With ActiveChart.Axes(xlCategory)
        .CrossesAt = 1
        .TickLabelSpacing = 1
        .TickMarkSpacing = 1
        .AxisBetweenCategories = True
        .ReversePlotOrder = False
    End With 


Merci de votre attention !

1 réponse

rafou29 Messages postés 29 Date d'inscription lundi 8 mars 2010 Statut Membre Dernière intervention 14 avril 2010 1
1 avril 2010 à 16:16
J'ai finit par trouver la solution à mon problème.


Voici le code pour ceux que sa intéresse :


.PivotTables("TCD1").PivotFields("Ligne").Orientation = xlPageField  
3
Rejoignez-nous