我生成在Excel 2002的枢轴图表与宏,使用日期字段作为图表报告过滤器(场取向设置为xlPageField)。我想这个透视字段的默认选择的值设置为在日期领域的最新值。什么是做在VBA正确的语法?

有帮助吗?

解决方案

你能不能在所有的项目为pagefield循环?下面是一个透视表,但得到它的图表工作不应该是什么大不了的:

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

其他提示

你不就是要选择的单元格已动态创建图表后?

是这样的:

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( “ fieldName的”)。当前页= “ fieldValue方法

这是从Excel 2003,但我相信2002年将是相似的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top