|
- Sub test()
- Dim d As Object
- Dim arr, brr
- Dim r%, i%
- Dim ws As Worksheet
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:f" & r)
- End With
- For i = 1 To UBound(arr)
- If Not d.Exists(arr(i, 1)) Then
- ReDim brr(1 To 9)
- For j = 1 To UBound(arr, 2)
- brr(j) = arr(i, j)
- Next
- brr(9) = 2
- d(arr(i, 1)) = brr
- End If
- Next
-
- With Worksheets("sheet2")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:c" & r)
- End With
- For i = 1 To UBound(arr)
- If d.Exists(arr(i, 1)) Then
- brr = d(arr(i, 1))
- brr(9) = 1
- Else
- ReDim brr(1 To 9)
- brr(1) = arr(i, 1)
- brr(9) = 3
- End If
- For j = 1 To 2
- brr(j + 6) = arr(i, j + 1)
- Next
- d(arr(i, 1)) = brr
- Next
- With Worksheets("sheet3")
- .UsedRange.Offset(1, 0).ClearContents
- .Range("a2").Resize(d.Count, 9) = Application.Transpose(Application.Transpose(d.Items))
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("a1:i" & r).Sort key1:=.Range("i2"), order1:=xlAscending, header:=xlYes
- .Columns("i:i").Clear
- End With
- End Sub
复制代码 |
|