Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Looping though sheets in workbook

I have the following code to loop through each sheet in the workbook and
format the columns to Autofit:

For Each Worksheet In ActiveWorkbook.Worksheets
Cells.Select
Selection.EntireColumn.AutoFit
Next

It only seems to Autofit the columns on the first sheet and all the others
remain unchanged except that they have all cells selected. Can anyone advise
as to what I am doing wrong here? or a better way to do this?
--
K Hogwood-Thompson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Looping though sheets in workbook

For Each ws In ActiveWorkbook.Worksheets
ws.Columns.AutoFit
Next

Don't use Worksheet as variable name.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"KHogwood-Thompson" wrote in
message ...
I have the following code to loop through each sheet in the workbook and
format the columns to Autofit:

For Each Worksheet In ActiveWorkbook.Worksheets
Cells.Select
Selection.EntireColumn.AutoFit
Next

It only seems to Autofit the columns on the first sheet and all the others
remain unchanged except that they have all cells selected. Can anyone
advise
as to what I am doing wrong here? or a better way to do this?
--
K Hogwood-Thompson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Looping though sheets in workbook

Thanks Bob, I will remember that in the future. Works prefectly now !!
--
K Hogwood-Thompson


"Bob Phillips" wrote:

For Each ws In ActiveWorkbook.Worksheets
ws.Columns.AutoFit
Next

Don't use Worksheet as variable name.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"KHogwood-Thompson" wrote in
message ...
I have the following code to loop through each sheet in the workbook and
format the columns to Autofit:

For Each Worksheet In ActiveWorkbook.Worksheets
Cells.Select
Selection.EntireColumn.AutoFit
Next

It only seems to Autofit the columns on the first sheet and all the others
remain unchanged except that they have all cells selected. Can anyone
advise
as to what I am doing wrong here? or a better way to do this?
--
K Hogwood-Thompson




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
Looping through sheets ReportSmith Excel Programming 4 April 3rd 07 06:20 PM
Looping a column in workbook 1 to workbook 2's sheets L. Howard Kittle Excel Programming 6 March 15th 06 03:14 PM
Looping through Sheets Jim Thomlinson[_3_] Excel Programming 3 September 25th 04 03:48 AM
Looping through Sheets dalejrstwin Excel Programming 0 September 24th 04 06:43 PM


All times are GMT +1. The time now is 02:45 PM.

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

About Us

"It's about Microsoft Excel"