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作者: pureshadow 时间: 2012-9-14 14:53
又代码,呵呵。。。。。
Excel技巧之合并单元格系列:不规则区域合并单元格的批量操作: http://support.microsoft.com/kb/2607855/zh-cn