|
Sub test()
Dim rng As Range
Dim maxHeight As Integer
Dim i As Integer
Dim j As Integer
Dim A
'1)辅助区域
Set rng = Sheets(2).[a1]
rng.NumberFormat = "@"
rng.WrapText = True
'2)非合并单元格,也自适应行高
Application.ScreenUpdating = False
Sheets(1).UsedRange.EntireRow.AutoFit
Sheets(1).UsedRange.ColumnWidth = 8.38
'3)合并单元格
A = Sheets(1).UsedRange
For i = 1 To UBound(A)
maxHeight = 0 '每行中,合格单元格最大的行高值
For j = 1 To UBound(A, 2)
If Cells(i, j) <> "" And Cells(i, j).MergeCells And Cells(i, j).Address = Cells(i, j).MergeArea.Cells(1).Address Then
' Debug.Print Cells(i, j).Address, Cells(i, j).MergeArea.Width, Cells(i, j).Value
'辅助单元格的列宽=合并单元格所在列宽
rng.ColumnWidth = 8.38 * Cells(i, j).MergeArea.Columns.Count
'放入值,以便自行改变行高
rng.Value = Cells(i, j).Value
'如果有了更大的行高,就更新maxHeight
If rng.Height > maxHeight Then maxHeight = rng.Height
'设置行高
Cells(i, j).RowHeight = maxHeight
End If
Next j
Next i
End Sub
4.rar
(15.98 KB, 下载次数: 3)
|
|