Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
nwacct
 
Posts: n/a
Default Autofit didn't work to adjust row height to fit wrapped contents


--
nwacct
  #2   Report Post  
Posted to microsoft.public.excel.misc
Paul Lautman
 
Posts: n/a
Default Autofit didn't work to adjust row height to fit wrapped contents

nwacct wrote:

Try this:

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


  #3   Report Post  
Posted to microsoft.public.excel.misc
nwacct
 
Posts: n/a
Default Autofit didn't work to adjust row height to fit wrapped conten

Thanks, Paul, but this is Greek to me - is your reply something I would paste
somewhere in my spreadsheet or something I need to do more "globally" to the
Excel in my PC?
--
nwacct


"Paul Lautman" wrote:

nwacct wrote:

Try this:

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



  #4   Report Post  
Posted to microsoft.public.excel.misc
Paul Lautman
 
Posts: n/a
Default Autofit didn't work to adjust row height to fit wrapped conten

nwacct wrote:
Thanks, Paul, but this is Greek to me - is your reply something I
would paste somewhere in my spreadsheet or something I need to do
more "globally" to the Excel in my PC?

nwacct wrote:

Try this:

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


It is a Macro to be put into a Module


  #5   Report Post  
Posted to microsoft.public.excel.misc
nwacct
 
Posts: n/a
Default Autofit didn't work to adjust row height to fit wrapped conten

Thanks, again. Can't believe I would have to go to all this trouble just to
get the row to adjust. Funny, it seems they sometimes adjust and sometimes
don't. I'll just do it manually - don't have that many times I put that much
in a cell.
--
nwacct


"Paul Lautman" wrote:

nwacct wrote:
Thanks, Paul, but this is Greek to me - is your reply something I
would paste somewhere in my spreadsheet or something I need to do
more "globally" to the Excel in my PC?

nwacct wrote:

Try this:

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


It is a Macro to be put into a Module



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
Autofit for row height is not working. Why? Leo Excel Discussion (Misc queries) 3 July 28th 08 06:43 PM
Need code to Autofit Row Height on recalculation Bob Tarburton Excel Discussion (Misc queries) 0 March 4th 05 08:31 PM
Autofitting a row Josephine Excel Discussion (Misc queries) 2 March 3rd 05 03:37 PM
Autofit row height in merged cells BobT Excel Discussion (Misc queries) 1 February 25th 05 04:44 PM
How do I make Excel automatically adjust a row's height once I in. sueuy Excel Worksheet Functions 1 December 2nd 04 05:35 PM


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

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

About Us

"It's about Microsoft Excel"