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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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