合并前
合并后,自动合并居中
实现代码
Sub mergeall()
Dim x As Long, y As Integer
x = Selection.Rows.Count
y = Selection.Columns.Count
a = Selection.Row
b = Selection.Column
Application.DisplayAlerts = False
For i = 1 To x
For j = 1 To y - 1
Cells(a + i - 1, b) = Cells(a + i - 1, b) & Cells(a + i - 1, b + j)
Next
Cells(a + i - 1, b).Resize(1, y).Select
Selection.Merge
Selection.HorizontalAlignment