|
Option Explicit
Sub TEST6()
Dim ar, br, n&, i&, j&, r&, dic As Object, strKey, strJoin$
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = Worksheets(2).[A1].CurrentRegion.Value
For i = 2 To UBound(ar)
strKey = Format(ar(i, 1), "yyyy-mm")
If Not dic.exists(strKey) Then
dic(strKey) = Array(strKey, ar(i, 2), ar(i, 2))
Else
br = dic(strKey)
If br(1) < ar(i, 2) Then
br(1) = ar(i, 2)
End If
br(2) = br(2) & "," & ar(i, 2)
dic(strKey) = br
End If
Next i
ReDim ar(1 To dic.Count, 1 To 3)
For j = 0 To dic.Count - 1
r = r + 1: strJoin = ""
br = dic.items()(j)
n = br(1): strKey = "," & br(2) & ",": strJoin = ""
ar(r, 1) = dic.keys()(j)
ar(r, 2) = 1 & "到" & n
For i = 1 To n
If InStr(strKey, "," & i & ",") = 0 Then strJoin = strJoin & "、" & i
Next
ar(r, 3) = IIf(Len(strJoin), Mid(strJoin, 2), "编号未缺失")
Next j
[E1].CurrentRegion.Offset(1).Clear
[E2].Resize(UBound(ar), 3) = ar
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|