![]() |
textstring to worksheet range
Hi Group,
Filling a range by below code; For i = 1 to 25 Sheets("Sheet1").Range("A1") = Sheets("Sheet1").Range("A1") & Sheets("Sheet2").Cells(1,i) Next The Range("A1") is a merged cell (A1:O1). It is formatted as WrapText. Is there a way to autosize the rowheigth of A1? The length of the text may vary from just one word to 4 lines in A1. If a text is "manualy" written into A1 by linebreaks it will automatically size by the lines. This is not happening when the text is "pasted" by code. The Row Autofit seems not do the trick. Must there be forced linebreaks to make it work? Thanks for some help. Brgds CG Rosén PS: Thanks Gary for the help with my last question, it works fine! |
textstring to worksheet range
Autofit does not work with merged cells.
You can perhaps use code posted by Jim Rech: 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 "CG Rosén" wrote in message ... Hi Group, Filling a range by below code; For i = 1 to 25 Sheets("Sheet1").Range("A1") = Sheets("Sheet1").Range("A1") & Sheets("Sheet2").Cells(1,i) Next The Range("A1") is a merged cell (A1:O1). It is formatted as WrapText. Is there a way to autosize the rowheigth of A1? The length of the text may vary from just one word to 4 lines in A1. If a text is "manualy" written into A1 by linebreaks it will automatically size by the lines. This is not happening when the text is "pasted" by code. The Row Autofit seems not do the trick. Must there be forced linebreaks to make it work? Thanks for some help. Brgds CG Rosén PS: Thanks Gary for the help with my last question, it works fine! |
All times are GMT +1. The time now is 12:32 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com