|
Sub 排序()
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With ActiveSheet
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:b" & r)
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("d1:e" & rs)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = ""
End If
Next i
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
d(Trim(br(i, 1))) = ""
End If
Next i
For Each k In d.keys
m = m + 1
n = 0
ReDim arr(1 To UBound(ar), 1 To 2)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) = k Then
n = n + 1
For j = 1 To 2
arr(n, j) = ar(i, j)
Next j
End If
Next i
If n > 0 Then
If m = 1 Then
.Cells(2, 8).Resize(n, 2) = arr
Else
ms = .Cells(Rows.Count, 8).End(xlUp).Row + 1
ws = .Cells(Rows.Count, 11).End(xlUp).Row + 1
If ms >= ws Then
hs = ms
Else
hs = ws
End If
.Cells(hs, 8).Resize(n, 2) = arr
End If
End If
n = 0
ReDim arr(1 To UBound(br), 1 To 2)
For i = 2 To UBound(br)
If Trim(br(i, 1)) = k Then
n = n + 1
For j = 1 To 2
arr(n, j) = br(i, j)
Next j
End If
Next i
If n > 0 Then
If m = 1 Then
.Cells(2, 11).Resize(n, 2) = arr
Else
hs = ""
ms = .Cells(Rows.Count, 8).End(xlUp).Row
For s = 2 To ms
If Trim(.Cells(s, 8)) = k Then
hs = s
Exit For
End If
Next s
If hs = "" Then
hs = ms
Else
hs = hs
End If
.Cells(hs, 11).Resize(n, 2) = arr
End If
End If
Next k
End With
MsgBox "ok!"
End Sub
|
评分
-
2
查看全部评分
-
|