如何通过VBA启用数据透视表的「同一列显示下一字段标签(紧凑形式)」选项?
Got it, let's sort this out for you! The code you're currently using targets the outline layout, which is why it's not giving you the compact form you need. The correct property value for the "compact form" option is xlCompact—that's the key switch here.
Target a Specific Pivot Field
If you want to apply the compact layout to just one particular pivot field, use this adjusted code:
ActiveSheet.PivotTables("Name of pivot table").PivotFields("Name of pivot field").LayoutForm = xlCompact
Apply to All Row Fields at Once
If you want the entire row area of your pivot table to use the compact form (so all subsequent field labels show up in the same column), you can set the row axis layout directly on the pivot table:
ActiveSheet.PivotTables("Name of pivot table").RowAxisLayout xlCompactRow
Just swap out "Name of pivot table" and "Name of pivot field" with your actual pivot table name and field name, and this should do exactly what you're looking for.
内容的提问来源于stack exchange,提问作者Misen

