Bonjour le Forum,
Je cherche de l'aide afin de m'aider à résoudre mon problème d'ajout addfield Rawfield lorsque conditionné dynamiquement. Dans le code qui suit j'ai la ligne suivante qui recherche dans un tableau si un des éléments est commun, si c'est le cas alors j'indique qu'il sera visible dans le champ Rawfield.
Hors je n'arrive pas à mettre au point l'ajout addfield Rawfield si un autre élément du tableau est commun ... j'espère que vous comprendrez sinon n'hésitez pas.
MErci d'avance,
Chrysto
Mon Code complét
If MyTableauElement(j) = monPivIt.Name Then monPivIt.Visible = True Else monPivIt.Visible = False
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 81
|
Public Function MakePivotTable_bis(Names, MyTableauElement, element As String) As Variant 'a remettre Names
Dim pt As PivotTable
Dim strField As String, PTOutputName As String
Dim WSD As Worksheet
Set WSD = Worksheets(Names) 'Set WSD = Worksheets("caresrpt-05Nov2009")
Dim PTOutput As Worksheet
Dim PTCache As PivotCache
Dim PRange As Range
Dim i As Integer
WSD.Select
Set PTOutput = Worksheets.Add(After:=Worksheets(WSD.Name))
PTOutput.Name = "titi" & Worksheets.Count
WSD.Select 'Worksheets(Name).Select
' Find the last row with data
Dim finalRow As Long
finalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp).Row
' Find the last column with data
Dim finalCol As Long
finalCol = WSD.Cells(6, Application.Columns.Count).End(xlToLeft).column
' Find the range of the data
Set PRange = WSD.Cells(6, 1).Resize(finalRow, finalCol)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange)
' Create the pivot table
Set pt = PTCache.CreatePivotTable(TableDestination:=PTOutput.Cells(1, 1), _
TableName:="Tableau_Pivot" & "_" & PTOutput.Name)
' Define the layout of the pivot table
' Set update to manual to avoid recomputation while laying out
pt.ManualUpdate = True
' Set up the row fields
'pt.AddFields RowFields:=Array( _
"Product")
Dim monPivIt As Object
With pt.PivotFields(element)
.Orientation = xlRowField
For Each monPivIt In .PivotItems
For j = 0 To UBound(MyTableauElement)
If MyTableauElement(j) = monPivIt.Name Then monPivIt.Visible = True Else monPivIt.Visible = False
'MsgBox monPivIt.Name
Next j
Next monPivIt
On Error Resume Next
'.AddFields RowFields:=Array("Product")
'.PivotItems("9412 eNodeB").Visible = False
'.PivotItems("9471 MME").Visible = False
'.PivotItems("(vide)").Visible = False
End With
' Set up the data fields
With pt.PivotFields("Ticket")
.Orientation = xlDataField
.Function = xlCount
.Position = 1
End With
With pt.PivotFields("AR state")
.Orientation = xlColumnField
.Position = 1
'.PivotItems("(vide)").Visible = False
If .PivotItems("(vide)").Visible = True Then
.PivotItems("(vide)").Visible = False
End If
End With
' Now calc the pivot table
pt.ManualUpdate = False
WSD.Select
End Function |
Partager