Sub 排序()
Dim i%, k%, x%, y%, arr, brr, temp,d,dic
Set d = CreateObject("scripting.dictionary")
Set dic = CreateObject("scripting.dictionary")
Sheet1.Activate
arr = Range("A3:D" & Cells(Rows.Count, 2).End(xlUp).Row)
For i = 1 To UBound(arr)
d(arr(i, 2)) = i
Next
Sheet2.Activate
brr = Range("A2:D" & Cells(Rows.Count, 2).End(xlUp).Row)
For k = 1 To UBound(brr)
dic(brr(k, 2)) = brr(k, 1) & "-" & brr(k, 3) & "-" & brr(k, 4)
Next
For x = 1 To UBound(brr) - 1
For y = x + 1 To UBound(brr)
If d(brr(x, 2)) > d(brr(y, 2)) Then
temp = brr(x, 2)
brr(x, 2) = brr(y, 2)
brr(y, 2) = temp
End If
Next
Next
For j = 1 To UBound(brr)
brr(j, 1) = Split(dic(brr(j, 2)), "-")(0)
brr(j, 3) = Split(dic(brr(j, 2)), "-")(1)
brr(j, 4) = Split(dic(brr(j, 2)), "-")(2)
Next
Sheet3.Range("A10").Resize(UBound(brr), 4) = brr
End Sub |