Copy data from a Pivot table in one worksheet ot another

前端 未结 1 1926
花落未央
花落未央 2021-01-23 14:13

I have two workbooks; in one I have a Pivot table; in the other, an empty worksheet.

I am trying to copy certain data from the pivot table to the other workbook, but it

相关标签:
1条回答
  • 2021-01-23 14:41

    Try the code below, explanations inside the code's comments :

    Option Explicit
    
    Sub CopyPivotItemsDataRange()
    
    Dim PvtTbl As PivotTable
    Dim PvtFld As PivotField
    Dim PvtRng As Range
    
    ' set the Pivot-Table object
    Set PvtTbl = cevesa.Worksheets("r_hora").PivotTables("r_hora")
    
    ' set the Pivot-Table Field object
    Set PvtFld = PvtTbl.PivotFields("PARAM")
    
    With PvtFld
        .ClearAllFilters
        ' use Union to merge multipe Pivot Items DataRange
        Set PvtRng = Union(.PivotItems("DEM(MW)").DataRange, .PivotItems("DEM_AGREGADA(MW)").DataRange, _
                    .PivotItems("POT(MW)").DataRange, .PivotItems("POT_HID(MW)").DataRange)
    End With
    
    PvtRng.Copy
    
    ' I let you finish the Paste section
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题