View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
RealmSteel[_2_] RealmSteel[_2_] is offline
external usenet poster
 
Posts: 9
Default Merged cell auto row height revisited

I seem to hit a deadend in the following topic, but came across another
idea.
http://groups.google.com/group/micro...9 a0b49426a28

What I am trying to do is make a merged cell automatically adjust the
row height if the text is longer than the cell width.
The merged cells are all formatted to wrap text.

Here is what the code looks like:

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

The problem with this code is that it only works when you first select
the cell.
What we have to do is type the text, navigate away and reselect the
cell.

I want it to run it's routine when the enter key is pressed or you
navigate away from the active cell.

How can this code be changed to accomplish this?

Another option would be to have it continuously scan a range or column.
Above row 12, the cells are not merged, so I don't know if this would
be a problem.