Autofit columns in different sheet when double click value cell in Pivot Table

mlee3

Board Regular
Joined
May 6, 2008
Messages
70
Hello. I'm in Excel 2007 pivot table. A different sheet with source data show up when you double click the value cell inside the pivot table. My questions is how to make the columns autofit in the source data sheet. For example, the data source has 12 rows and 11 columns and all 11 columns are the same width. Is there any way (may be using VBA?) to automatically adjust the column width based on the contents.

Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello

Just stumbled upon this topic, which seems to have had not a lot of attention.
Since I came here through Google, I bet other users will face the same problem. Hence, my solution.

Well, this is possible through VBA. You could add this event to the ThisWorkbook section of the VBA code:

Code:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
    Sh.UsedRange.Columns.AutoFit
End Sub

When Excel creates the new sheet, this oneliner is fired.
When you create a new sheet in any other way, this code is fired as well, but does not have any side effects
(since for a new sheet, autofitting the usedrange of cell A1 is harmless).

HTH.
 
Upvote 0

Forum statistics

Threads
1,224,259
Messages
6,177,485
Members
452,782
Latest member
ZCapitao

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