Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Autofit column width of all worksheets in active workbook - an example

No question here, just a procedure for the archive.

Search criteria: Autofit auto fit width of all columns in an worksheets work sheets
active workbook justify width all column in work book automatically
programmatically macro to resize column width

Sub ColumnsAutoFitAllSheets()
'AutoFit all column widths in all worksheets in workbook

Application.ScreenUpdating = False
For i = 1 To Sheets.Count
Sheets(i).Select
Cells.EntireColumn.AutoFit
Range("A1").Select
Next
Application.ScreenUpdating = True


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Autofit column width of all worksheets in active workbook - an example

DataFreakFromUtah,

A bit shorter and a bit more explicit,

'*****
Sub test()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Columns.AutoFit
Next
End Sub
'*****

Variants:

For Each wks In ThisWorkbook.Worksheets
For Each wks In ActiveWorkbook.Worksheets
For Each wks In Workbooks("Book1").Worksheets

--

Also, your code will crash if there is a Chart sheet in the workbook.

Regards,
Anders Silven

"DataFreakFromUtah" skrev i meddelandet
om...
No question here, just a procedure for the archive.

Search criteria: Autofit auto fit width of all columns in an worksheets work

sheets
active workbook justify width all column in work book automatically
programmatically macro to resize column width

Sub ColumnsAutoFitAllSheets()
'AutoFit all column widths in all worksheets in workbook

Application.ScreenUpdating = False
For i = 1 To Sheets.Count
Sheets(i).Select
Cells.EntireColumn.AutoFit
Range("A1").Select
Next
Application.ScreenUpdating = True


End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofit row text (wrapped) without changing column width? kimdnw Excel Discussion (Misc queries) 6 August 17th 07 03:15 AM
format:column width: autofit selection dutch3dsmax Setting up and Configuration of Excel 1 March 28th 07 08:27 AM
autofit cells in column width Boethius1 Excel Discussion (Misc queries) 5 April 12th 06 02:51 AM
Autofit Row height or Column Width does not work Gunjani Excel Discussion (Misc queries) 2 October 11th 05 09:19 PM
autofit Column width- Ajit Ajit Munj Excel Discussion (Misc queries) 2 February 24th 05 05:51 PM


All times are GMT +1. The time now is 12:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"