Column widths !

Tarqs

Board Regular
Joined
Feb 14, 2011
Messages
120
Can anyone add column widths to this code for me please ?

I need to eithter auto re-size or carry over the original cell width? I have 4 columns of data in A:D

Code:
Sub Explode()
    ActiveSheet.PivotTables("PivotTable1").ShowPages PageField:="Supplier"
End Sub

help much appreciated

Thanks

Tarqs
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
Sub Explode()
    ActiveSheet.PivotTables("PivotTable1").ShowPages PageField:="Supplier"
    Application.ScreenUpdating = False
    ActiveSheet.Columns("A").ColumnWidth = Sheets("Sheet1").Columns("A").ColumnWidth
    ActiveSheet.Columns("B").ColumnWidth = Sheets("Sheet1").Columns("B").ColumnWidth
    ActiveSheet.Columns("C").ColumnWidth = Sheets("Sheet1").Columns("C").ColumnWidth
    ActiveSheet.Columns("D").ColumnWidth = Sheets("Sheet1").Columns("D").ColumnWidth
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sorry, typing with thumbs today!

The code only applies the column widths to the first of newly created sheets and not all sheets that the show pages function creates.

eg column widths applied to 1 out of the 10 "pages" created.

Tarqs
 
Upvote 0
Thought i'd provide an update as i got this answered via another thread (Can I lock every sheet) thanks to MrKowz! Slightly different solution as it is autofit and not actual widths but it works for my needs.

Code:
Sub ExplodeTotal()
Dim shtcnt  As Long, _
    i       As Long
 
shtcnt = Sheets.Count
Application.ScreenUpdating = False
ActiveSheet.PivotTables("PivotTable1").ShowPages PageField:="Supplier"
For i = shtcnt To Sheets.Count
    Sheets(i).Cells.EntireColumn.AutoFit
    Sheets(i).Protect Password:="abc123"
Next i
Application.ScreenUpdating = True
End Sub

Tarqs
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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