Maintaining pivot table column widths

peterbel

New Member
Joined
Jan 5, 2012
Messages
28
Is there a way using VB to make sure that when pivot tables are refreshed their column widths are NOT changed?

I have about 10 pivot tables on a spreadsheet tab, all derived from a master table on another tab. When I add new data to the master I refresh the derived tables using VB behind a button on the sheet. Excel then decides to alter column widths making a lot of the data unreadable unless widths are reset.

Thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Without VB
- set separately for each table

Pivot Table Options \ Layout and Format \ uncheck Preserve Cell Formatting on Update
 
Last edited:
Upvote 0
Using VBA

Single pivot table, using its name
Code:
ActiveSheet.PivotTables("PT1").HasAutoFormat = False

or loop entire workbook like this
Code:
Sub KeepFormat()
    Dim ws As Worksheet, pt As PivotTable
    For Each ws In ThisWorkbook.Worksheets
        For Each pt In ws.PivotTables
           pt.HasAutoFormat = False
        Next pt
    Next ws
End Sub
 
Upvote 0
Thanks for your repies.
I have tried the 'manual' alteration first so I can test it does as expected. I will add the VB if it does.
Saved me a lot of re-formatting time, thanks.
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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