VBA Center Align Pivot Table Columns

CalRich1023

New Member
Joined
Mar 15, 2021
Messages
48
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I have a Pivot Table that I would like 3 columns center aligned on, but I can't seem to get it working. It gives me an error every time I run it. Could someone point out my mistake here?

Thank you!

VBA Code:
Sub PivotTable_Collapse()

    Dim pT As PivotTable
    Dim pF As PivotField

    Set pT = ActiveSheet.PivotTables(1)

    With pT
        For Each pF In pT.RowFields
            pF.DrillTo pF.Name
        Next pF
    End With

'GENERAL FORMATTING
    Range("M6:O").Select
        With Selection
            .HorizontalAlignment = xlCenter
        End With
     
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Range("M6:O" & Range("O" & Rows.Count).End(xlUp).Row).Select
 
Upvote 0
Solution

Forum statistics

Threads
1,215,242
Messages
6,123,830
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