|
Sub 整理数据()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 6).End(xlUp).Row
If r < 2 Then MsgBox "数据源为空!": End
ar = .Range("a1:i" & r)
End With
Dim br()
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) = "" Then
For j = 1 To 5
ar(i, j) = ar(i - 1, j)
Next j
End If
zf = ar(i, 1) & "|" & ar(i, 2)
d(zf) = ""
Next i
For Each k In d.keys
n = n + 1
For i = 2 To UBound(ar)
zf = ar(i, 1) & "|" & ar(i, 2)
If zf = k Then
For j = 1 To UBound(ar, 2)
If j <> 6 And j <> 7 Then
br(n, j) = ar(i, j)
End If
Next j
If br(n, 6) = "" Then
br(n, 6) = ar(i, 6) & ar(i, 7) & ar(i, 8)
Else
br(n, 6) = br(n, 6) & "," & ar(i, 6) & ar(i, 7) & ar(i, 8)
End If
br(n, 7) = br(n, 7) + ar(i, 7)
End If
Next i
Next k
With Sheets("整理")
.[a1].CurrentRegion.Offset(1) = Empty
.[a2].Resize(n, UBound(br, 2)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|