Had to do this today for a project - thought it might be useful as you cannot use Excel's built in features to Autofit Row heights with word wrap enabled on cells that are merged.
This function will allow the cell range you specify to autofit the row height so all text is visible in a merged range.
Here is a demo of Excel Failing to do so VS this function being awesome. NOTE: i left screenupdating on just for demo - use in script will not show the rows resizing/adjusting, only final product.
Thanks and Enjoy!
AHK Being Awesome:
Function with usage
xl := ComObjActive("Excel.Application")
;Range is defined as the first cell in the 'merged range' or the top left most cell
;For example if you had merged cells A1:F1 - you need only specify A1 for this script.
;Or to autofit a whole range specify like below:
Range = B4:B25
xlrange := xl.activesheet.range(Range)
RangeColumns := xlRange.Columns.Count
For Rows in xlRange
Cell := xl.activesheet.range(rows.address)
MergedRange := xl.activesheet.range(Rows.Address).mergearea
oWidth := Rows.ColumnWidth
for Columns in Mergedrange.columns
tWidth += columns.ColumnWidth
tWidth += 3
Cell.Rows.ColumnWidth := tWidth
cell.wraptext := 1
nHeight := cell.RowHeight
cell.RowHeight := nHeight
cell.ColumnWidth := oWidth