Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Sizing row height automatically

I'm trying to automatically resize the row height after merging cells in a
row and wrapping the text. Is there a way to do this.

My code so far is:
ActiveSheet.Range(.Cells(3, 2), .Cells(3, 5)).MergeCells = True
ActiveSheet.Cells(3, 2).WrapText = True

The data being inserted into this range is being pulled from an Access text
field so I need the row height to automatically adjust depending on how much
data is extracted. If I don't merge the cells the row will automatically
adjust its height but won't if they are merged.

Stewart



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sizing row height automatically

Autosize doesn't work for merged cells.

You can adapt this code previously posted by Jim Rech:

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

"Stewart Allen" wrote in message
...
I'm trying to automatically resize the row height after merging cells in a
row and wrapping the text. Is there a way to do this.

My code so far is:
ActiveSheet.Range(.Cells(3, 2), .Cells(3, 5)).MergeCells = True
ActiveSheet.Cells(3, 2).WrapText = True

The data being inserted into this range is being pulled from an Access

text
field so I need the row height to automatically adjust depending on how

much
data is extracted. If I don't merge the cells the row will automatically
adjust its height but won't if they are merged.

Stewart





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Sizing row height automatically

Thanks for that.


"Tom Ogilvy" wrote in message
...
Autosize doesn't work for merged cells.

You can adapt this code previously posted by Jim Rech:

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

"Stewart Allen" wrote in message
...
I'm trying to automatically resize the row height after merging cells in

a
row and wrapping the text. Is there a way to do this.

My code so far is:
ActiveSheet.Range(.Cells(3, 2), .Cells(3, 5)).MergeCells = True
ActiveSheet.Cells(3, 2).WrapText = True

The data being inserted into this range is being pulled from an Access

text
field so I need the row height to automatically adjust depending on how

much
data is extracted. If I don't merge the cells the row will automatically
adjust its height but won't if they are merged.

Stewart







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
Adjust row height automatically Jinghui Excel Discussion (Misc queries) 0 May 8th 08 03:23 AM
Automatically re-sizing merged cells LongTermNoob Excel Worksheet Functions 1 March 28th 07 10:42 AM
automatically sizing text with graphs Shoque Charts and Charting in Excel 1 August 2nd 06 03:30 PM
resizing row height automatically? Gumby Excel Discussion (Misc queries) 2 July 11th 05 04:13 PM
Sizing windows automatically tom Troyer Excel Programming 1 July 9th 03 04:43 AM


All times are GMT +1. The time now is 06:35 AM.

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"