Help Understanding a Snippet of Code

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I was recently trying to code for a pivot table to collapse some row fields, and ran into the underlying code. It works, but I don't really understand it. I will likely have to build more code with pivot tables, so I'm hoping someone can help me understand this snippet...specifically how PF.Name collapses all of the row fields to the first one. I would've assumed that I would have to actually enter the row field I wanted the table collapsed to.
VBA Code:
With PT
    For Each PF In PT.RowFields
        PF.DrillTo PF.Name
    Next PF
End With
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
i am also not that familiar with pivot tables and their coding, but this code made sense after i looked up the method being applied to the pivot field.

assuming that PT is a PivotTable type and PF is a PivotField, when you use the .DrillTo method, it collapses that field's section in the pivot table (like the way you can collapse fields on a subtotaled list).

 
Upvote 0
i am also not that familiar with pivot tables and their coding, but this code made sense after i looked up the method being applied to the pivot field.

assuming that PT is a PivotTable type and PF is a PivotField, when you use the .DrillTo method, it collapses that field's section in the pivot table (like the way you can collapse fields on a subtotaled list).

Right...I think the .Name portion is throwing me off.
 
Upvote 0

Forum statistics

Threads
1,215,241
Messages
6,123,824
Members
449,127
Latest member
Cyko

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