Option Explicit
Sub Test()
Dim i&, ii&, Rah, xR As Range
For i = [C65536].End(3).Row To 1 Step -1
If Cells(i, 3).MergeArea.Count > 1 And Cells(i, 3) <> "" Then
Set xR = Cells(i, 3).MergeArea
For ii = 2 To Cells(i, 3).MergeArea.Count
Rah = Rah + xR(ii).RowHeight
Next
Cells(i, 3).UnMerge
Rows(i).AutoFit
xR.Merge
Rows(i).RowHeight = Rows(i).RowHeight - Rah
Rah = 0
End If
Next
End Sub作者: hugh0620 時間: 2024-5-15 18:10
Option Explicit
Sub TEST_RxC()
Dim i&, ii&, Rah, CaW, xR As Range, R&, cW, cW1, C%, N
N = 1 '如果後方多出空白N值改大例如:1.2,如果後方字元被遮住N值改小例如:0.8
For i = 1 To [C65536].End(3).MergeArea.Row
If Cells(i, 3).MergeArea.Count > 1 And Cells(i, 3) <> "" Then
Set xR = Cells(i, 3).MergeArea
C = xR.Columns.Count
R = xR.Rows.Count
cW1 = xR(1).Columns.ColumnWidth
For ii = 1 To C
CaW = CaW + xR(ii).Columns.ColumnWidth
Next
For ii = 2 To R
Rah = Rah + xR(ii).Rows.RowHeight
Next
xR.UnMerge
xR(1).Columns.ColumnWidth = CaW + xR.Font.Size / CaW * N
Rows(i).AutoFit
xR.Merge
xR(1).Columns.ColumnWidth = cW1
xR(1).Rows.RowHeight = xR(1).Rows.RowHeight - Rah + xR.Font.Size * 0.5
Rah = 0: CaW = 0
End If
Next
End Sub作者: Andy2483 時間: 2024-5-17 08:17