文件太大,上传不了,请参考以下代码
Sub 按钮1_Click()
Dim i As Long, x As Long, n As Long, r As Long
Dim arr, a
r = Cells(Rows.Count, 6).End(xlUp).Row
arr = Cells(1, 6).Resize(r, 2)
For i = 2 To UBound(arr)
arr(i, 1) = Replace(arr(i, 1), "/", "/-")
a = Split(arr(i, 1), "-")
For x = 0 To UBound(a) - 1
If Val(a(x)) + 1 = Val(a(x + 1)) Then
n = n + 1
a(x) = Empty
Else
If n > 0 Then
a(x) = Empty
n = 0
End If
End If
Next 'x,a
Cells(i, 7) = Empty
For x = 0 To UBound(a)
If a(x) <> Empty Then
If Cells(i, 7) = Empty Then
Cells(i, 7) = a(x)
Else
Cells(i, 7) = Cells(i, 7) & "-" & a(x)
End If
End If
Next 'x
Cells(i, 7) = Replace(Cells(i, 7), "/-", "/")
Next 'i
End Sub |