View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
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