sintassi:
ActiveSheet.PivotTables("NOME TABELLA").PivotFields("NOME CAMPO")
esempio: tabella "Riepilogo" mettere il campo "Tipo" nella riga nella posizione 2
With ActiveSheet.PivotTables("Riepilogo").PivotFields("Tipo")
.Orientation = xlRowFieldEnd With
.Position = 2
esempio: creo un array che mi inserisce nelle varie posizioni le righe che mi interessano
Dim righe(3)
righe(1) = "Nome"
righe(2) = "Cognome"
righe(3) = "Anno"
For x = 1 To 3
With ActiveSheet.PivotTables("PIVOT").PivotFields(righe(x))Next x.Orientation = xlRowFieldEnd With
.Position = x
esempio: tolgo la riga Tipo
ActiveSheet.PivotTables("PIVOT").PivotFields("Tipo").Orientation = xlHidden
sintassi inserimento:
ActiveSheet.PivotTables("PIVOT").Adddata Field ActiveSheet.PivotTables("PIVOT").PivotFields("CAMPO"), "etichetta del campo", FUNZIONE
sintassi:
ActiveSheet.PivotTables("PIVOT").PivotFields("CAMPO").PivotItems("valore da filtrare").Visible = True/False
esempio di filtro:
With ActiveSheet.PivotTables("PIVOT").PivotFields("CAMPO")
.PivotItems("").Visible = TrueEnd With
.PivotItems("(blank)").Visible = False
esempio: creo un filtro automatco tramite un ciclo for e un controllo if
Dim filtro As PivotItem dichiaro la variabile come Item della pivot
For Each filtro In ActiveSheet.PivotTables("TABELLA").PivotFields("CAMPO").PivotItems
If filtro = "xxx" Or filtro = "yyy" ThenNext filtrofiltro.Visible = TrueElsefiltro.Visible = FalseEnd If
per togliere i filtri e ripristinare tutti i dati si usa: .ClearAllFilters
esempio
ActiveSheet.PivotTables("Riepilogo").PivotFields("Campo").ClearAllFilters
sintassi:
ActiveSheet.PivotTables("PIVOT").PivotFields("CAMPO").AutoSort TIPO, "CAMPO"
esempio:
ActiveSheet.PivotTables("Situazioni_aperte").PivotFields("Mediatore").AutoSort xlAscending, "Mediatore"
sintassi:
ActiveSheet.PivotTables().Count
esempio: memorizzo quante tabelle ci sono nel foglio
numero = ActiveSheet.PivotTables().Count
sintassi:
ActiveSheet.PivotTables("NOME TABELLA").PivotCache.Refresh
PT.PivotCache.RefreshNext PT