2024-04-21 04:22:44
2024-04-21 04:56:18
我这个不一定就是到9啊,最多有可能到999的哦~~~
//我只是写了个原理,代码不太清晰,你如下该一下
Sub run()
Dim row As Integer
Dim str As String
Dim id As Integer
Dim idarr(1000) As Integer
Dim outstr As String
Dim i As Integer
Dim j As Integer
Dim Bool As Boolean
row = 1
Do
str = Sheets("Sheet1").Cells(row, 1)
If str = "" Then Exit Do
id = Val(Mid(str, 12, 4))
idarr(id - 1) = id
row = row + 1
Loop
outstr = ""
Bool = False
For i = 0 To 998
If idarr(i) = 0 Then
idarr(i) = i + 1
Else
idarr(i) = 0
End If
Next
i = 0
Bool = True
While i 0 Then
If idarr(i + 1) = 0 Then
If (i + 1) 9 Then
outstr = outstr & idarr(i) & ","
Else
outstr = outstr & idarr(i)
End If
Bool = True
End If
If (idarr(i + 1) 0) And Bool Then
outstr = outstr & idarr(i) & "-"
Bool = False
End If
End If
i = i + 1
Wend
If Mid(outstr, Len(outstr), 1) = "," Then outstr = Mid(outstr, 1, Len(outstr) - 1)
MsgBox outstr
End Sub