'单号是有序的。7楼的代码有问题,这个应该是可以的,自己先测试一下。
Option Explicit
Sub abc()
Dim i, p, r
Call doevent(False)
[d:d].MergeCells = False
p = 1
r = Cells(Rows.Count, "c").End(xlUp).row
For i = 2 To r
If Cells(i, "c").Value <> Cells(i + 1, "c").Value Or i = r Then
If i - p > 1 Then Cells(p + 1, "d").Resize(i - p).Merge
p = i
End If
Next
Call doevent(True)
End Sub
Function doevent(flag As Boolean)
With Application
.DisplayAlerts = flag
.ScreenUpdating = flag
End With
End Function