ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   RowHeight automatically change when user does ALT+ENTER for linefe (https://www.excelbanter.com/excel-programming/310012-re-rowheight-automatically-change-when-user-does-alt-enter-linefe.html)

Tom Ogilvy

RowHeight automatically change when user does ALT+ENTER for linefe
 
Merged cells won't autofit for row height.

here is some code written by Jim Rech

which sizes the rowheight for a merged cell. Perhaps you can incorporate a
similar approach in your code.

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

--
Regards,
Tom Ogilvy

"GaryZ" wrote in message
...
Hi,

I have a VFP program that generates a spreadsheet.

In the generated spreadsheet, I have a cell merged across columns A

through
D used for a multiline comment.

For the cell, I have WordWrap = True. However, when the user puts a

linefeed
into the comment via ALT+ENTER, the RowHeight does not adjust and only one
line of the comment is visible.

Is there any way, while generating the spreadsheet, to mark the cell with
automatically adjustable rowheight?

Here is the source for the cell definition.

m_row = m_row + 1
strrow = ALLT(STR(m_row))
.Range("A"+strrow+":D"+strrow).mergecells = True
With .Range("A"+strrow)
.WrapText = True
.HorizontalAlignment = xlLeft
EndWith





All times are GMT +1. The time now is 12:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com