PC Review


Reply
Thread Tools Rate Thread

How to Autofit column when cells have Wrapped Text?

 
 
nomail1983@hotmail.com
Guest
Posts: n/a
 
      3rd Sep 2007
Using macro record mode, I created a macro that inserts a row, sets
the format alignment to Right with Wrap Text selected, then inserted
titles in each cell, some which include chr(10) to create multi-line
titles. The VBA looks like this:

Rows("1:1").Select : Selection.Insert Shift:=xlDown
With Selection
.HorizontalAlignment = xlRight : .VerticalAlignment = xlBottom
.WrapText = True : .Orientation = 0 : .AddIndent = False
.IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder =
xlContext
.MergeCells = False
End With
Range("A1").Select : ActiveCell.FormulaR1C1 = "Year"
Range("B1").Select : ActiveCell.FormulaR1C1 = "Your" & Chr(10) &
"Age"
[... etc ...]

Since some of the original columns are not wide enough, the text wraps
within the too-narrow limits of the cell.

I tried to correct that by manually highlighting all columns, then
clicking on Format Column Autofit Selection. That generated the
following VBA code:

Columns("A:N").Select : Selection.Columns.AutoFit

But that failed to widen the columns to accomodate the text up to the
line break [chr(10)].

I can widen the columns to accomodate the text up to the line break,
both manually and in VBA?

(Actually, if you tell me how to do it manually, I can learn the VBA
using macro record mode.)

 
Reply With Quote
 
 
 
 
nomail1983@hotmail.com
Guest
Posts: n/a
 
      3rd Sep 2007
On Sep 3, 1:14 am, "nomail1...@hotmail.com" <nomail1...@hotmail.com>
wrote:
> I can widen the columns to accomodate the text up to the line break,
> both manually and in VBA?


That should have read: "How can I widen ...?".

I have a workable solution. I select the columns, set the column
width to something "far too big", __then__ do the Autofit. In VBA:

Columns("A:O").Select
Selection.ColumnWidth = 30 : Selection.Columns.autoFit

Of course, 30 is arbitrary -- good enough for my purposes.

I'm still open to a better idea.

 
Reply With Quote
 
guy
Guest
Posts: n/a
 
      4th Sep 2007
how about setting the WrapText = FALSE, then Columns.Autofit ?

<(E-Mail Removed)>
???????:(E-Mail Removed)...
> On Sep 3, 1:14 am, "nomail1...@hotmail.com" <nomail1...@hotmail.com>
> wrote:
>> I can widen the columns to accomodate the text up to the line break,
>> both manually and in VBA?

>
> That should have read: "How can I widen ...?".
>
> I have a workable solution. I select the columns, set the column
> width to something "far too big", __then__ do the Autofit. In VBA:
>
> Columns("A:O").Select
> Selection.ColumnWidth = 30 : Selection.Columns.autoFit
>
> Of course, 30 is arbitrary -- good enough for my purposes.
>
> I'm still open to a better idea.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofit row text (wrapped) without changing column width? =?Utf-8?B?a2ltZG53?= Microsoft Excel Misc 5 17th Aug 2007 03:15 AM
Autofit in cells with multiple lines of wrapped text. =?Utf-8?B?Sm9obiBLZWl0aA==?= Microsoft Excel Programming 4 15th Feb 2006 07:00 PM
Re: Autofit merged cells with wrapped text Dave Peterson Microsoft Excel Programming 2 3rd Dec 2004 03:35 AM
Autofit merged cells with wrapped text =?Utf-8?B?SXZhbg==?= Microsoft Excel Programming 0 23rd Jun 2004 02:33 PM
How to autofit row height on merged cells with wrapped text Bob Lemay Microsoft Excel Misc 1 29th Jan 2004 06:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 AM.