合并单元格的行高自动调整
一、思路
二、单行代码
Function adjustMergeRowheight(r, firstc, endc)
Rows(r).Select
Rows(r).AutoFit
RowHeight = Rows(r).Height
For Each rng In Range(Cells(r, firstc), Cells(r, endc)).Cells
rng.Select
If rng.MergeCells Then
rng.WrapText = True
colindex = rng.Column
If colindex = rng.MergeArea.Column Then
oriwidth = Columns(colindex).ColumnWidth
colwidth = 0
maxc = colindex + rng.MergeArea.Columns.Count - 1
For i = colindex To maxc
colwidth = colwidth + Columns(i).ColumnWidth
Next
rng.UnMerge
Columns(colindex).ColumnWidth = colwidth
Rows(r).AutoFit
If Rows(r).Height > RowHeight Then
RowHeight = Rows(r).Height
End If
Columns(colindex).ColumnWidth = oriwidth
With Range(Cells(r, colindex), Cells(r, maxc))
.WrapText = True
.Merge
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlHAlignLeft
End With
End If
End If
Next
Rows(r).RowHeight = RowHeight * 1.25
End Function