合并同列多组相邻相同的单元格(excel宏)
右键SHEET标签,选择查询代码,复制粘贴下面的代码,关闭窗口,按ALT+F8,选择执行!
Sub MergeSameCells()
Dim lRow As Integer
Application.DisplayAlerts = False
With ActiveSheet
lRow = .Range("A65536").End(xlUp).Row
For i = lRow To 2 Step -1
If .Cells(i, 1).Value = .Cells(i - 1, 1).Value Then
.Range(.Cells(i - 1, 1), .Cells(i, 1)).Merge
End If
Next
End With
Application.DisplayAlerts = True
End Sub
心得:仅对第一列有效,可以把后面的剪切过来,多次运行,还是很快的。
相关主题