ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code to change column widths? (https://www.excelbanter.com/excel-programming/424307-code-change-column-widths.html)

babs

Code to change column widths?
 
I am running code to open a workbook and then I want to set all columns in
the workbook to 15.
I use:
..Workbooks.Open "C:\Shared\Report Info.xlsx"
..Columns.ColumnWidth = 15
This code only works on the first sheet in the workbook, but I need it to
work for all sheets.
Can someone please help me?
TIA

Bernard Liengme

Code to change column widths?
 
Sub tryme()
Application.ScreenUpdating = False
For Each wk In Worksheets
Columns.ColumnWidth = 15
Next
Application.ScreenUpdating = True
End Sub

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"BABs" wrote in message
...
I am running code to open a workbook and then I want to set all columns in
the workbook to 15.
I use:
.Workbooks.Open "C:\Shared\Report Info.xlsx"
.Columns.ColumnWidth = 15
This code only works on the first sheet in the workbook, but I need it to
work for all sheets.
Can someone please help me?
TIA




Chip Pearson

Code to change column widths?
 

Columns.ColumnWidth = 15

should be
Wk.Columns.ColumnWidth = 15

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

On Wed, 18 Feb 2009 10:14:43 -0400, "Bernard Liengme"
wrote:

Sub tryme()
Application.ScreenUpdating = False
For Each wk In Worksheets
Columns.ColumnWidth = 15
Next
Application.ScreenUpdating = True
End Sub

best wishes


Bernard Liengme

Code to change column widths?
 
Ooops, many thanks for corrections
--
Bernard

"Chip Pearson" wrote in message
...

Columns.ColumnWidth = 15

should be
Wk.Columns.ColumnWidth = 15

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

On Wed, 18 Feb 2009 10:14:43 -0400, "Bernard Liengme"
wrote:

Sub tryme()
Application.ScreenUpdating = False
For Each wk In Worksheets
Columns.ColumnWidth = 15
Next
Application.ScreenUpdating = True
End Sub

best wishes





All times are GMT +1. The time now is 10:32 AM.

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