Adjust Column width on sheet

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have several Pivot tables and slicers on this sheet.

When I select any one of the slicers some columns are tooo small resulting in in #### being displayed

I have set up the following code on sheet Monthly Data to prevent this from happening after selecting a slicer

It would be appreciated if someone could assist me. The Data Range if from Col A to AD


Code:
 Private Sub Worksheet_Activate()
Sheets("Monthly Data").Cells.EntireColumn.AutoFit
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
IS this what you want ???
Code:
Sheets("Monthly Data").Columns("A:AD").EntireColumn.AutoFit
 
Upvote 0
So, how does your approach not do what you want? Are the PTs on the sheet "Monthly Data"? Is the event for the same sheet?

I have several Pivot tables and slicers on this sheet.

When I select any one of the slicers some columns are tooo small resulting in in #### being displayed

I have set up the following code on sheet Monthly Data to prevent this from happening after selecting a slicer

It would be appreciated if someone could assist me. The Data Range if from Col A to AD


Code:
 Private Sub Worksheet_Activate()
Sheets("Monthly Data").Cells.EntireColumn.AutoFit
End Sub
 
Upvote 0
The PTs are on the same sheet as well as the event

The code below works if after selecting a filter on one of the slicers , I select another sheet and then select this sheet again

Code:
 Private Sub Worksheet_Activate()
Sheets("Monthly Data").Columns("A:AD").EntireColumn.AutoFit
End Sub
 
Last edited:
Upvote 0
You are using the wrong event!

Try the lightly tested (the below goes in the code module of the worksheet containing the pivottable):
Code:
Option Explicit

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    Target.TableRange2.EntireColumn.AutoFit
    Debug.Print "Event triggered"
    End Sub
The PTs are on the same sheet as well as the event

The code below works if after selecting a filter on one of the slicers , I select another sheet and then select this sheet again

Code:
 Private Sub Worksheet_Activate()
Sheets("Monthly Data").Columns("A:AD").EntireColumn.AutoFit
End Sub
 
Upvote 0
Thanks for the help. This code automatically adjusts the columns, each time I filter data using the slicer that is linked to the PT
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,237
Members
448,555
Latest member
RobertJones1986

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