|
这段代码是支持多列操作的.
Sub mergecells() '自动合并单元格
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim str As String
Dim i, b, j, c As Integer
i = Selection.Rows.count - 1
j = Selection.Columns.count
For c = 1 To j
str = ActiveCell.Address
For b = 1 To i
With ActiveCell
.Select
If .Offset(1, 0) = .Value Then
Range(ActiveCell, .Offset(1, 0)).Select
Selection.mergecells = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
Else
.Offset(1, 0).Select
End If
End With
Next
Range(str).Offset(0, 1).Select
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub |
|