我有一個數據透視表,用於在"part"
上彙總"coverage"
僅適用於接受的零件。從數據透視表提取數據vba
我想然後提取"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
我得到一個運行時錯誤「424」,對象上
Sheets("Destination").Range("G" & NEWi) = PivotTable.GetPivotData(data_field, Range("I" & i), 「Coverage」)
需要這將是寫這條線的正確方法?
您的數據透視表對象是'PT'而不是'PivotTable' – Rory
替換「數據透視表'與'PT'仍然給出錯誤'運行時錯誤1004應用程序定義或對象定義的錯誤' –
@ L.Dutch而不是'循環'嘗試'TableRange2'(參見我的代碼) –