Je crée un TCD contenant des champs calculés avec VBA. Ensuite, je souhaite
changer une partie des pivotfields (notamment des champs calculés) et là,
cela plante.
Si ce n'est pas un champs calculé, un pivotfield.orientation =xlhidden
marche masi si c'en est un, impossible ! Pourtant si je demande à
l'enregistreur de macro, il me sort la même chose...
voila en sheet 1 j'ai
A B
1 NR COS
2 100 50
3 150 70
et le code suivant qui plante quand je veux retirer GM :
With ActiveSheet.PivotTables("PivotTable2")
.PivotFields("Sum of NR").Orientation = xlHidden
'la ca marche nickel
.PivotFields("Sum of GM").Orientation = xlHidden
'pouf cela ne veut plus
End With
End Sub
Function make_fields(field As String, position As Integer, style As String,
pivotname As String)
With ActiveSheet.PivotTables(pivotname).PivotFields(field)
.Orientation = xlDataField
.NumberFormat = style
.Function = xlSum
.position = position
End With
make_fields = position + 1
End Function
Comment peut on le retirer (autrement qu'à la main :-) ?
Cordialement
Benjamin
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
isabelle
bonjour poypoy,
malheureusement la propriété Visible = False s'applique seulement aux PivotItems avec cette ligne,
.PivotFields("Sum of NR").Orientation = xlHidden
tu enlève ce champ du tcd, tu ne peux pas l'enlever une deuxième fois puisqu'il n'est plus là, si tu veux le remettre il faut ajouter cette ligne
With ActiveSheet.PivotTables("PivotTable2") .PivotFields("Somme de NR").Orientation = xlHidden waggle = make_fields("NR", waggle, "#,##0.00", "PivotTable2") End With
il reste un problème au niveau de la position dans la function que tu peux résoudre avec,
x = ActiveSheet.PivotTables("PivotTable2").PivotFields.Count
With ActiveSheet.PivotTables("PivotTable2") .PivotFields("Sum of NR").Orientation = xlHidden 'la ca marche nickel .PivotFields("Sum of GM").Orientation = xlHidden 'pouf cela ne veut plus End With
End Sub Function make_fields(field As String, position As Integer, style As String, pivotname As String) With ActiveSheet.PivotTables(pivotname).PivotFields(field) .Orientation = xlDataField .NumberFormat = style .Function = xlSum .position = position End With make_fields = position + 1
End Function
Comment peut on le retirer (autrement qu'Ã la main :-) ? Cordialement Benjamin
bonjour poypoy,
malheureusement la propriété Visible = False s'applique seulement aux PivotItems
avec cette ligne,
.PivotFields("Sum of NR").Orientation = xlHidden
tu enlève ce champ du tcd, tu ne peux pas l'enlever une deuxième fois puisqu'il n'est plus là,
si tu veux le remettre il faut ajouter cette ligne
With ActiveSheet.PivotTables("PivotTable2")
.PivotFields("Somme de NR").Orientation = xlHidden
waggle = make_fields("NR", waggle, "#,##0.00", "PivotTable2")
End With
il reste un problème au niveau de la position dans la function que tu peux résoudre avec,
x = ActiveSheet.PivotTables("PivotTable2").PivotFields.Count
With ActiveSheet.PivotTables("PivotTable2")
.PivotFields("Sum of NR").Orientation = xlHidden
'la ca marche nickel
.PivotFields("Sum of GM").Orientation = xlHidden
'pouf cela ne veut plus
End With
End Sub
Function make_fields(field As String, position As Integer, style As String,
pivotname As String)
With ActiveSheet.PivotTables(pivotname).PivotFields(field)
.Orientation = xlDataField
.NumberFormat = style
.Function = xlSum
.position = position
End With
make_fields = position + 1
End Function
Comment peut on le retirer (autrement qu'Ã la main :-) ?
Cordialement
Benjamin
malheureusement la propriété Visible = False s'applique seulement aux PivotItems avec cette ligne,
.PivotFields("Sum of NR").Orientation = xlHidden
tu enlève ce champ du tcd, tu ne peux pas l'enlever une deuxième fois puisqu'il n'est plus là, si tu veux le remettre il faut ajouter cette ligne
With ActiveSheet.PivotTables("PivotTable2") .PivotFields("Somme de NR").Orientation = xlHidden waggle = make_fields("NR", waggle, "#,##0.00", "PivotTable2") End With
il reste un problème au niveau de la position dans la function que tu peux résoudre avec,
x = ActiveSheet.PivotTables("PivotTable2").PivotFields.Count
With ActiveSheet.PivotTables("PivotTable2") .PivotFields("Sum of NR").Orientation = xlHidden 'la ca marche nickel .PivotFields("Sum of GM").Orientation = xlHidden 'pouf cela ne veut plus End With
End Sub Function make_fields(field As String, position As Integer, style As String, pivotname As String) With ActiveSheet.PivotTables(pivotname).PivotFields(field) .Orientation = xlDataField .NumberFormat = style .Function = xlSum .position = position End With make_fields = position + 1
End Function
Comment peut on le retirer (autrement qu'Ã la main :-) ? Cordialement Benjamin