A
Adev111
Hi,
I am having problems with row heights of merged cells. It works almost
perfect. The problem comes in when the text in the cell is two or three
lines. For instance if the merged cell initial width is 50 and initial
height is 13.5, n the text is about such that it fits in two lines i.e.
"asdfdsafasdfkjasdfjadsfsadfadsfdsafadsfdsafasdfsadf..." initially all
text not visible
After I run this function I see the text like this
"asdfdsafasdfkjasdfjadsfsadfadsfdsafadsfdsafasdfsadf
asfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasd
"
This results in taking up more height for the row. As you can see, it
only needs about two rows to fit in text. Now I have sorta gotten close
to where the problem could be, it could be in the statement :
PossNewRowHeight = .RowHeight
So if I do PossNewRowHeight = .RowHeight -
curentRowHeight
The above appears expected, but it messes up the logic and the other
rows do not get merged right and seems like no formatting gets done.
Would someone please suggest where the problem could be?
Thank You
Adev111
here's the function I found from google groups
Sub AutoFitMergedCellRowHeight()
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
I am having problems with row heights of merged cells. It works almost
perfect. The problem comes in when the text in the cell is two or three
lines. For instance if the merged cell initial width is 50 and initial
height is 13.5, n the text is about such that it fits in two lines i.e.
"asdfdsafasdfkjasdfjadsfsadfadsfdsafadsfdsafasdfsadf..." initially all
text not visible
After I run this function I see the text like this
"asdfdsafasdfkjasdfjadsfsadfadsfdsafadsfdsafasdfsadf
asfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasd
"
This results in taking up more height for the row. As you can see, it
only needs about two rows to fit in text. Now I have sorta gotten close
to where the problem could be, it could be in the statement :
PossNewRowHeight = .RowHeight
So if I do PossNewRowHeight = .RowHeight -
curentRowHeight
The above appears expected, but it messes up the logic and the other
rows do not get merged right and seems like no formatting gets done.
Would someone please suggest where the problem could be?
Thank You
Adev111
here's the function I found from google groups
Sub AutoFitMergedCellRowHeight()
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