|
'哈哈哈,还有什么特例吗,我看看你还能加几个
Option Explicit
Sub test()
Dim i, j, row, a, b
Application.DisplayAlerts = False
row = Cells(Rows.Count, "a").End(xlUp).row + 1
For i = 4 To row
a = getnum(Cells(i, "a").Value)
For j = i + 1 To row
b = getnum(Cells(j, "a"))
If b - a = 1 Then
a = b
Else
If IsNumeric(Cells(j, "a")) And IsNumeric(Cells(j - 1, "a")) Then
a = Val(Cells(j - 1, "a")): b = Val(Cells(j, "a"))
If Val(Right(b, IIf(Len(a) = Len(b), 1, 2))) - Val(Right(a, 1)) <> 1 Then
Cells(i, "a").Resize(j - i).Merge
i = j - 1: Exit For
Else
a = b
End If
ElseIf Len(a) > 1 And Len(b) > 1 Then
If Val(Right(b, IIf(Len(a) = Len(b), 1, 2))) - Val(Right(a, 1)) <> 1 Then
Cells(i, "a").Resize(j - i).Merge
i = j - 1: Exit For
Else
a = b
End If
Else
Cells(i, "a").Resize(j - i).Merge
i = j - 1: Exit For
End If
End If
Next j, i
Application.DisplayAlerts = True
End Sub
Function getnum(t) As Long
Dim i
If Not IsNumeric(t) Then
For i = Len(t) To 1 Step -1
If Not IsNumeric(Mid(t, i, 1)) Then
getnum = Val(Mid(t, i + 1)): Exit Function
End If
Next
End If
getnum = Val(t)
End Function |
评分
-
1
查看全部评分
-
|