ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Resize columns for all sheets in a workbook (https://www.excelbanter.com/excel-programming/361569-resize-columns-all-sheets-workbook.html)

Xluser@work[_2_]

Resize columns for all sheets in a workbook
 
I am trying to resize the columns in all sheets of a workbook and I have a
number of workbooks each with a different number of sheets.

The code I have so far is:

For Each Worksheet In ActiveWorkbook.Worksheets
Columns("A:A").EntireColumn.ColumnWidth = 30.71
Columns("B:B").EntireColumn.ColumnWidth = 8.57
Columns("C:C").EntireColumn.ColumnWidth = 8.57
Columns("D:D").EntireColumn.ColumnWidth = 8.57
Columns("E:E").EntireColumn.ColumnWidth = 8.57
Columns("F:F").EntireColumn.ColumnWidth = 8.57
Columns("G:G").EntireColumn.ColumnWidth = 2.14
Columns("H:H").EntireColumn.ColumnWidth = 8.57
Columns("I:I").EntireColumn.ColumnWidth = 8.57
Columns("J:J").EntireColumn.ColumnWidth = 8.57
Columns("K:K").EntireColumn.ColumnWidth = 8.57
Columns("L:L").EntireColumn.ColumnWidth = 8.57
Next Worksheet
End Sub

It appears to iterate through each worksheet based on display update but
only corrects the column widths on the active sheet at the time the code is
run. Can anyone advise how I force the code to carry out the instruction on
each sheet?

Thanks for any help.

Norman Jones

Resize columns for all sheets in a workbook
 
Hi XlUser,

Try:

'=============
Public Sub Tester()
Dim SH As Worksheet

For Each SH In ActiveWorkbook.Worksheets
With SH
.Columns("A:A").EntireColumn.ColumnWidth = 30.71
.Columns("B:F").EntireColumn.ColumnWidth = 8.57
.Columns("G:G").EntireColumn.ColumnWidth = 2.14
.Columns("H:L").EntireColumn.ColumnWidth = 8.57
End With
Next SH
End Sub
'<<=============


--
---
Regards,
Norman



"Xluser@work" wrote in message
...
I am trying to resize the columns in all sheets of a workbook and I have a
number of workbooks each with a different number of sheets.

The code I have so far is:

For Each Worksheet In ActiveWorkbook.Worksheets
Columns("A:A").EntireColumn.ColumnWidth = 30.71
Columns("B:B").EntireColumn.ColumnWidth = 8.57
Columns("C:C").EntireColumn.ColumnWidth = 8.57
Columns("D:D").EntireColumn.ColumnWidth = 8.57
Columns("E:E").EntireColumn.ColumnWidth = 8.57
Columns("F:F").EntireColumn.ColumnWidth = 8.57
Columns("G:G").EntireColumn.ColumnWidth = 2.14
Columns("H:H").EntireColumn.ColumnWidth = 8.57
Columns("I:I").EntireColumn.ColumnWidth = 8.57
Columns("J:J").EntireColumn.ColumnWidth = 8.57
Columns("K:K").EntireColumn.ColumnWidth = 8.57
Columns("L:L").EntireColumn.ColumnWidth = 8.57
Next Worksheet
End Sub

It appears to iterate through each worksheet based on display update but
only corrects the column widths on the active sheet at the time the code
is
run. Can anyone advise how I force the code to carry out the instruction
on
each sheet?

Thanks for any help.





All times are GMT +1. The time now is 07:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com