首页 文章

数据透视图报表过滤器/页面字段的默认值

提问于
浏览
0

我在Excel 2002中使用宏生成数据透视表,使用日期字段作为图表报告过滤器(将字段方向设置为xlPageField) . 我想将此pivotfield的默认选定值设置为日期字段中的最新值 . 在VBA中执行此操作的正确语法是什么?

3 回答

  • 0

    你不能遍历该页面的所有项目吗?这是一个数据透视表,但让它适用于图表应该不是什么大不了的事:

    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
    
  • 0

    您是否只想在动态创建图表后选择单元格?

    就像是:

    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
    
  • 0

    chartObject.PivotLayout.PivotTable.PivotFields(“fieldName ").CurrentPage = " fieldValue”

    这是来自Excel 2003,但我认为2002年将是类似的

相关问题