|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:h" & r)
- For i = 1 To UBound(arr)
- arr(i, 3) = CDate(arr(i, 3))
- arr(i, 4) = CDate(arr(i, 4))
- Next
- .Range("a2:h" & r) = arr
- .Range("a2:h" & r).Sort key1:=.Range("b2"), order1:=xlAscending, key2:=.Range("c2"), order2:=xlAscending, Header:=xlNo
- arr = .Range("a2:h" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- ReDim brr(1 To 2)
- brr(1) = arr(i, 2)
- Else
- brr = d(arr(i, 2))
- End If
- brr(2) = brr(2) & vbLf & arr(i, 3) & Space(1) & arr(i, 4) & Space(1) & arr(i, 5) & Space(1) & arr(i, 6) & Space(1) & arr(i, 7) & Space(1) & arr(i, 8)
- d(arr(i, 2)) = brr
- Next
- ReDim crr(1 To d.Count, 1 To 2)
- m = 0
- For Each aa In d.keys
- brr = d(aa)
- If Len(brr(2)) <> 0 Then
- brr(2) = Mid(brr(2), 2)
- End If
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- .Range("a2:h" & r).Sort key1:=.Range("a2"), order1:=xlAscending, Header:=xlNo
-
- End With
- With Worksheets("sheet2")
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(UBound(crr), UBound(crr, 2)) = crr
- End With
-
- End Sub
复制代码 |
|