copy column from pivot table

djsmarties

Board Regular
Joined
Sep 10, 2002
Messages
95
Hi,

another pivot table question.

I have a pivot table that looks like this

Count of record
Days emplyoyee count
1-2 xxx1 1
xxx2 1
3-4 xxx3 1
5-6 xxx4 1

What I need is to copy the list of employees and the count for each specific grouping of days to another spreadsheet.
Is it somehow possible to adapt this code that I am using to copy the total of each row?

With Worksheets("pivot_T").PivotTables(1).DataBodyRange
.Columns(.Columns.Count).Copy Worksheets("pivot_T").Range("H5")
End With


Thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Do you mean?

Code:
Sub Test()
    With Worksheets("pivot_T").PivotTables(1)
        With .RowRange.Offset(1, 0).Resize(.RowRange.Rows.Count - 1)
            .Columns(2).Copy Worksheets("pivot_T").Range("H5")
            .Columns(1).Copy Worksheets("pivot_T").Range("I5")
            With Worksheets("pivot_T").Range("I5").Resize(.Rows.Count)
                .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
                .NumberFormat = "@"
                .Value = .Value
            End With
        End With
        .DataBodyRange.Copy Worksheets("pivot_T").Range("J5")
    End With
End Sub
 
Upvote 0
Yes that is almost what I wanted. I adapted your code to create a macro that would select only one of the "day groupings" and then copy the employee names and the grand total:


Sub sla_email_03()
With ActiveSheet.PivotTables("PivotTable1").PivotFields("day grouping")
.PivotItems("4-5 days").Visible = False
.PivotItems("over 5").Visible = False
End With
With Worksheets("pivot_day").PivotTables(1)
With .RowRange.Offset(1, 0).Resize(.RowRange.Rows.Count - 1)
.Columns(2).Copy Worksheets("pivot_day").Range("H5")

End With
With Worksheets("pivot_day").PivotTables(1).DataBodyRange
.Columns(.Columns.Count).Copy Worksheets("pivot_day").Range("I5")
End With
End With
End Sub


Thanks a lot for getting me started, I am slowly managing to get into writing code... :)

Actually, would it be possible to also copy the pivot field headings, so that when I copy the data, I also copy the headings?
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top