|
Sub test()
Dim dic As Object, i As Integer, arr, brr()
Dim n As Integer
n = 1
Set dic = CreateObject("scripting.dictionary")
With Sheet1
arr = .[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 4)
brr(1, 4) = "生产流水号"
For i = 1 To UBound(arr)
If arr(i, 3) = "" Then arr(i, 3) = arr(i - 1, 3)
Next i
For i = 2 To 4
brr(1, i - 1) = arr(1, i)
Next i
For i = 2 To UBound(arr)
x = arr(i, 3) & "-" & arr(i, 4)
If dic.exists(x) = False Then
n = n + 1
dic(x) = n
brr(n, 1) = arr(i, 2)
brr(n, 2) = arr(i, 3)
brr(n, 3) = arr(i, 4)
brr(n, 4) = arr(i, 8) & ","
Else
brr(dic(x), 1) = brr(dic(x), 1) + arr(i, 2)
brr(dic(x), 4) = brr(dic(x), 4) & arr(i, 8) & ","
End If
Next i
For i = 1 To n
brr(i, 4) = Left(brr(i, 4), Len(brr(i, 4)) - 1)
Next i
.[k7].Resize(n, 4) = brr
End With
End Sub |
|