Domanda

Sono la generazione di un grafico pivot in Excel 2002 con una macro, con un campo data come il filtro del report grafico (impostazione dell'orientamento campo per xlPageField). Vorrei impostare il valore selezionato di default di questo PivotField alla più recente valore nel campo data. Qual è la giusta sintassi per fare quello in VBA?

È stato utile?

Soluzione

Non potete scorrere tutti gli elementi per che pagefield? Ecco una tabella pivot, ma riuscite a farla lavorare per un grafico non dovrebbe essere un grosso problema:

Sub Main()
    Dim pvt As PivotTable
    Dim fld As PivotField
    Dim itm As PivotItem
    Dim m As Variant

    Set pvt = Worksheets(1).PivotTables(1)
    Set fld = pvt.PageFields(1)

    m = fld.PivotItems(1)
    For Each itm In fld.PivotItems
        If itm.Value > m Then m = itm.Value
    Next itm

    fld.CurrentPage = m
End Sub

Altri suggerimenti

Non vuoi solo per selezionare la cella dopo aver creato in modo dinamico il grafico?

Qualcosa di simile:

Dim value As Date
value = "1-apr-09"
Dim row As Integer
row = 0

Dim keeplooping As Boolean
keeplooping = True
While (keeplooping)
    row = row + 1
    If Range("B" & row).value = value Then
        keeplooping = False
        Range("B" & row).Select
        MsgBox ("found it")
    ElseIf Range("B" & row).value = "" Then
        keeplooping = False
        MsgBox ("Not found")
    End If
Wend

ChartObject .PivotLayout.PivotTable.PivotFields ( " nomeCampo "). CurrentPage = " fieldValue "

Questo è da Excel 2003 ma presumo 2002 saranno simili

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top