小编L.D*_*ica的帖子

从数据透视表VBA中提取数据

我有一个数据透视表汇总"coverage""part"仅接受部分。

在此处输入图片说明

然后,我想将其提取"sum of coverage"到另一张纸上。我写了以下宏:

Sub Pull_data()
'Update the pivot table
Sheets("Pivot").PivotTables("PivotTable2").PivotCache.Refresh
'clear all filters
Sheets("Pivot").PivotTables("PivotTable2").PivotFields("Accepted").ClearAllFilters
'filters only accepted items
Sheets("Pivot").PivotTables("PivotTable2").PivotFields("Accepted").CurrentPage = "YES"
'get the last row of the pivot table
Set PT = Sheets("Pivot").PivotTables("PivotTable2")
With PT.TableRange1
    lngLastRow = .rows(.rows.Count).Row
End With
For i = 4 To lngLastRow
    'copy the coverage to destination sheet
    NEWi = i + 10
    Sheets("Destination").Range("G" & NEWi) = PivotTable.GetPivotData(data_field, Range("I" & i), “Coverage”)
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)

我收到运行时错误“ 424”,对象为

Sheets("Destination").Range("G" …
Run Code Online (Sandbox Code Playgroud)

excel vba pivot-table excel-vba

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

excel ×1

excel-vba ×1

pivot-table ×1

vba ×1