View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RealmSteel[_2_] RealmSteel[_2_] is offline
external usenet poster
 
Posts: 9
Default Auto row height for merged cells

Jim,

I'm obviously doing something wrong.

I just created a new workbook and inserted the following code into
worksheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Rows.AutoFit
End Sub

I then merged 3 columns (B, C & D) in row 3, formatted them for left
justification and Wrap text.
I copy and pasted these cells for another 10 rows.

I verified the formatting for all the merged cells is Wrap Text.

I typed into one of the cells a line longer than the merged cell width
and nothing happened.

My version os Excell 2003 if that matters.

I did notice with the code from the link I provided in my first post,
the cell will auto adjust if I navigate back to it and then away.
All I have to do is select it and then select another cell. The row
will automatically adjust.
I'd like it to auto adjust as a soon as I navigate away.

Here is what the code looks like right now:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth +
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
End Sub

Thanks,
Rich


On Dec 11, 1:48 pm, Jim Jackson
wrote:
When I formatted some cells as "Wrap Text" and typed a sentence in one, made
sure only one line of text was showing and clicked "Enter", the cells resized
to show the complete text.

Are your cells already formatted to allow Wrapping of Text?

--
Best wishes,

Jim


text -- Hide quoted text -- Show quoted text -