【问题标题】:Referencing datarange of pivot table with multiple row fields引用具有多个行字段的数据透视表的数据范围
【发布时间】:2016-11-15 20:13:13
【问题描述】:

好的,我在列或行中使用单个数据透视字段引用数据透视表的数据范围:

BevPvt.PivotFields("Sum of Amount ").DataRange.Select
For Each deposit1 In BevPvt.PivotFields("Sum of Amount ").DataRange

等等

但是如果我在列或行中有多个数据字段,IE 将两个数据字段移动到行框(例如 POS 位置和日期)。我想找到匹配的日期和匹配的位置。将行字段(例如位置)移动到列的唯一解决方案是什么?

【问题讨论】:

    标签: excel vba pivot-table


    【解决方案1】:

    解决此问题的一种方法是使用 offset(0,-1)

    我关闭行字段框中第一个数据字段的小计,然后让我的宏搜索值字段数据范围 - 如果找到 vbNullString 则 offset(0,-1) 记录第一个数据字段的名称行字段位置,然后如果不是 vbNullString 则偏移量给出第二行字段位置中数据字段的名称。

    看起来像这样(小计的去除不在这部分代码中)

    For Each deposit2 In CHMBAll.PivotFields("Sum of Original Deposit Total").DataRange
    If deposit2 = vbNullString Then
    lockbox = deposit2.Offset(0, -1).Value
    End If
    If deposit2 <> vbNullString Then
    If deposit2.Interior.Color = 5296274 Then
    DepDate = deposit2.Offset(0, -1).Value
    For CHMBi = 2 To CHMBLR
    If Cells(CHMBi, 5).Value = lockbox Then
    If Cells(CHMBi, 3).Value = DepDate Then
    Cells(CHMBi, 6).Interior.Color = 5296274
    End If
    End If
    Next CHMBi
    End If
    End If
    Next deposit2
    

    【讨论】:

      猜你喜欢
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多