WrapText Property

H

Howard Kaikow

Excel's Help states:

"Microsoft Excel will change the row height of the range, if necessary, to
accommodate the text in the range."

Using the following, the row height does not change:
With rng
.MergeCells = True
.Value = str ' Some long string that should have to wrap
.WrapText = True
End With

Does not matter whether Value is set before/after WrapText.

Am I doing something wrong?
 
P

Peter T

Text in merged cells does not make the row height autosize/fit, even with
WrapText.

How best to fix will depend on how much you know about 'required' heights of
other cells in the row. In the simplest scenario start by setting the row's
height to default, and some/all of this

' trap original height
rng(1).MergeArea.MergeCells = False
rng.HorizontalAlignment = xlCenterAcrossSelection
rng(1).value = sLongText
rng.WrapText = True
' might need to autofit the row here
Ht = rng(1).Height
if origHeight > Ht then Ht = origHeight
rng.HorizontalAlignment = xlLeft
rng(1).EntireRow.RowHeight = Ht ' if mergearea is only one row

Of course simply doing the above might mess up larger heights in other
merged cells, so how much you'll need to check will depend on what you've
got.

From memory a macro by Jim Rech is often recommended to autofit merged cells
(search this group)

Regards,
Peter T
 
H

Howard Kaikow

Bob Phillips said:
Is the range more than one cell? That could be the problem.

Help states that the property applies to a RangeCollection, which is:

"Represents a cell, a row, a column, a selection of cells containing one or
more contiguous blocks of cells, or a 3-D range."

I have tried both Select and Activate on the range, still no height
adjustment,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top