Unfortunately, I haven't found a good solution.
The problem originates in a bug in Excel 2000. I do not know if it also applies to later versions.
The problem manifest it self when merging cells horizontally.
Row height fails to auto adjust when you have merged cells.
The following example code shows the problem
Dim r As Range
Set r = Sheet1.Range("B2")
Range(r, r(1, 2)).Merge
r.Value = ""
r.Value = "asdg lakj dsgl dfgjdfgj dgj dfgj dfgjdgjdfgjdfgjd"
r.WrapText = True
r.EntireRow.AutoFit
In this case r.EntireRow.AutoFit will not take into account that the text spans over several rows, and adjust the height as if it was single line of text.
You'll have the same problem when doing manual autofit (double clicking on the row-height-adjuster in the sheet) to a row that has merged cells and word wrap.
A solution (as suggested by Gary McGill ) is to use an unrelated sheet. Set the column width to match the full with of the merged cells. Copy the text, with the same formating. Let the cell auto-adjust and use that cells values.
Here follows a simplified example:
Public Sub test()
Dim widthInPoints As Double
Dim mergedCells As Range
Set mergedCells = Sheet1.Range("B2:C2")
widthInPoints = mergedCells.width
Dim testCell As Range
Set testCell = Sheet2.Range("A1")
testCell.EntireColumn.columnWidth = ConvertPointsToColumnWidth(widthInPoints, Sheet2.Range("A1"))
testCell.WrapText = True
testCell.Value = mergedCells.Value
'Text formating should be applied as well, if any'
testCell.EntireRow.AutoFit
mergedCells.EntireRow.rowHeight = testCell.rowHeight
End Sub
Private Function ConvertPointsToColumnWidth(widthInPoints As Double, standardCell As Range) As Variant
ConvertPointsToColumnWidth = (widthInPoints / standardCell.width) * standardCell.columnWidth
End Function