按ALT+F11,然后在左边点鼠标右键插入一个模块,输入以下内容后再按F5。
如有不明白可发邮件到
[email protected]Sub M1()
Dim EndRow, Arr1, Arr2(), MyUnion
EndRow = Cells(65536, 1).End(xlUp).Row
Arr1 = Range(Cells(2, 1), Cells(EndRow, 1))
ReDim Arr2(1 To UBound(Arr1, 1), 1 To 1)
Cells(2, "C").Resize(UBound(Arr1, 1), 1).Clear
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
x = 1
For i = 2 To UBound(Arr1, 1)
If Arr1(i, 1) = Arr1(i - 1, 1) Then
x = x + 1
If x = 3 Then
Arr2(i, 1) = 5
x = 0
End If
Else
Arr2(i - 1, 1) = 5
x = 1
End If
Next
Cells(2, "C").Resize(UBound(Arr2, 1), 1) = Arr2
Arr1 = Range(Cells(1, "C"), Cells(EndRow, "C"))
Set MyUnion = Cells(2, "C")
For i = 2 To EndRow
If Arr1(i, 1) = "" Then
Set MyUnion = Union(MyUnion, Cells(i, "C"))
Else
Set MyUnion = Union(MyUnion, Cells(i, "C"))
MyUnion.Merge
Set MyUnion = Cells(i + 1, "C")
End If
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub