Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
try this without selections
Sub fitcols() For Each ws In activeworkbook.worksheets ws.Columns.AutoFit Next ws End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Looping through sheets | Excel Programming | |||
Looping a column in workbook 1 to workbook 2's sheets | Excel Programming | |||
Looping through Sheets | Excel Programming | |||
Looping through Sheets | Excel Programming |