Re: Column width in Excel 2003
- From: aaronroessler@xxxxxxxxx
- Date: Fri, 18 Jan 2008 11:51:27 -0800 (PST)
On Dec 31 2007, 9:41 pm, "Rick Rothstein \(MVP - VB\)"
<rickNOSPAMn...@xxxxxxxxxxxxxxxxx> wrote:
I've read through this thread and I think you may be able to use this macro.
It lets you specify a "buffer factor" value (a number greater than 1) to
increase a column width by (for example, 1.1 will make a column 10% wider
than the AutoFit width) to create "extra" white space for the text UNLESS
the column width is already the buffer factor or more larger, in which case
that width is preserved. The buffer factor is specified in the Const
statement... I used 10% for my tests; but, perhaps, you can use 1.05 (5%
extra white space)... you will have to test to see what minimum buffer
factor you can get away with.
Sub SizeToFit()
Dim R As Range
Dim X As Long, z
Dim ColWidth As Double
Const Tolerance As Double = 1.1 '10% extra room
Set R = Worksheets("Sheet1").UsedRange
For X = R.Column To R.Columns.Count
ColWidth = Columns(X).ColumnWidth
If Worksheets("Sheet1").Cells(Rows.Count, X).End(xlUp).Row = 1 Then
If Worksheets("Sheet1").Cells(Rows.Count, X).Value = "" Then
GoTo Continue
End If
End If
Columns(X).AutoFit
If Tolerance * Columns(X).ColumnWidth < ColWidth Then
Columns(X).ColumnWidth = ColWidth
Else
Columns(X).ColumnWidth = Tolerance * Columns(X).ColumnWidth
End If
Continue:
Next
End Sub
Rick
"AnneK" <NoReturnema...@xxxxxxx> wrote in message
news:%23l2s7xaSIHA.2268@xxxxxxxxxxxxxxxxxxxxxxx
My Bureau Chief has an Excel 2003 document that he receives from our
finacial unit. When he tries to print the document out it shows ###### in
different cells throughout the entire document. In the past when he used
Excel 2000 he would just double click on the right hand side of the top of
the column and it would expand the column one character larger and would
print the whole number in each of those cells. In Excel 2003 when he does
this, it still shows the #####'s and he has to physically go in and move
the column over ever so slightly to get it to print out correctly. When
there are numerous columns that have this issue, it is very time
consuming. Is there another way to correct this that is fast and easy
rather than manually having to expand the column? He also does not want
to make all of the columns the same width as this would take up quite a
bit more paper when printing out.
PS Throughout each column there are different font sizes.
I would love to use this code as well, but i am getting an error. I am
using Excel 2004 on Mac OS X Leopard. The error i get is on this
line... Const Tolerance As Double = 1.1 '10% extra room - Syntax
error?
any ideas?
Thanks in Advance,
Aaron
.
- Follow-Ups:
- Re: Column width in Excel 2003
- From: aaronroessler
- Re: Column width in Excel 2003
- References:
- Re: Column width in Excel 2003
- From: Rick Rothstein \(MVP - VB\)
- Re: Column width in Excel 2003
- Prev by Date: Conditional Format cell colors changed.
- Next by Date: data analysis-multiple linear regression with Excel 2007
- Previous by thread: Re: Column width in Excel 2003
- Next by thread: Re: Column width in Excel 2003
- Index(es):
Relevant Pages
|