Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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!




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a character in a textstring Vix Excel Discussion (Misc queries) 2 September 28th 06 05:56 PM
Clean/replace textstring CG Rosén Excel Programming 1 September 17th 05 03:47 PM
"cut" textstring CG Rosén Excel Programming 3 September 2nd 05 01:46 AM
Can you get the range reference for each page in a worksheet print range? Crosby Excel Programming 3 April 12th 05 06:06 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM


All times are GMT +1. The time now is 02:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"