Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default How to Autofit column when cells have Wrapped Text?

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.)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default How to Autofit column when cells have Wrapped Text?

On Sep 3, 1:14 am, "
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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
guy guy is offline
external usenet poster
 
Posts: 12
Default How to Autofit column when cells have Wrapped Text?

how about setting the WrapText = FALSE, then Columns.Autofit ?


roups.com...
On Sep 3, 1:14 am, "
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofit row text (wrapped) without changing column width? kimdnw Excel Discussion (Misc queries) 6 August 17th 07 03:15 AM
Autofit in cells with multiple lines of wrapped text. John Keith[_2_] Excel Programming 4 February 15th 06 07:00 PM
Autofit Column Headers with wrapped text (Not a merged cell issue) Mark Excel Programming 0 September 13th 05 12:42 AM
Autofit merged cells with wrapped text Dave Peterson[_3_] Excel Programming 2 December 3rd 04 03:35 AM
Autofit merged cells with wrapped text Ivan Excel Programming 0 June 23rd 04 02:33 PM


All times are GMT +1. The time now is 10:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"