View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
tjtjjtjt tjtjjtjt is offline
external usenet poster
 
Posts: 51
Default Set Column Width

Thanks, Chip.
--
tj


"Chip Pearson" wrote:

Change "UsedRange" to "ActiveSheet.UsedRange".


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"tjtjjtjt" wrote in message
...
I would like to AutoFit all the columns in the UsedRange of a
worksheet
unless that would make the column wider than 40. In that case I
want to set
the column to 40.

I get an Object Required error 424 message when I attempt the
following:

Sub SetColWidth()
Dim col As Range

Cells.EntireColumn.AutoFit

For Each col In UsedRange
If col.ColumnWidth 40 Then
col.ColumnWidth = 40
End If
Next
End Sub


I just want to automate a report that my predecessor did
manually. Could
anyone supply me with a brief explanation of the mistake I've
made? I'd like
to avoid it in the future.
Thanks in advance for any help.
--
tj