» Adjust row height of merged cells using VBA in Microsoft Excel
CATEGORY - Formating in VBA
VERSION - All Microsoft Excel Versions
Merged cells do not have the correct height after a row break. How can I correct this?
Answer:
Insert the following code in the standard module.
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
Application.ScreenUpdating = True
End Sub
Book Store:
Recommended Books:
- Millionaire Real Estate Mentor : The Secrets of Financial Freedom through Real Estate Investing
- The Sweet Potato Queens' Big-Ass Cookbook and Financial Planner
- Managing by the Numbers: A Commonsense Guide to Understanding and Using Your Company's Financials: An Essential Resource for Growing Businesses
- Microsoft Office Xp: Advanced Concepts and Techniques: Word 2002, Excel 2002, Access 2002, Powerpoint 2002
- Marketing Planning for Services
- Cashflow Quadrant: Rich Dad's Guide to Financial Freedom
No comments have been submitted.

