|
- Sub t()
- Dim arr, brr, m%, i%, j%, dic, k, n%, p, r%
- Set dic = CreateObject("scripting.dictionary")
- m = Sheet1.Range("a2").End(4).Row
- arr = Sheet1.Range("a2:b" & m)
- ReDim p(1 To m)
- j = 1
- For i = 1 To UBound(arr)
- If arr(i, 2) = "Parent" Or arr(i, 2) = "" Then
- dic(arr(i, 1)) = dic(arr(i, 1)) + 1
- End If
- Next i
- n = 2
- For Each k In dic.keys
- Sheet2.Cells(n, 3) = k
- Sheet2.Cells(n, 4) = dic(k)
- n = n + 1
- Next k
- dic.RemoveAll
- With Sheet1
- For i = 1 To UBound(arr)
- If arr(i, 2) = "Parent" Or arr(i, 2) = "" Then
- dic(arr(i, 1)) = dic(arr(i, 1)) + 1
- If dic(arr(i, 1)) > 1 Then
- x = i + 1
- While .Cells(x, 1) = arr(i, 1)
- p(j) = .Cells(x, 1).Row
- x = x + 1: j = j + 1
- Wend
- i = x - 2
- End If
- End If
- Next i
- For i = UBound(p) To 1 Step -1
- If p(i) <> 0 Then
- Rows(p(i)).Delete shift:=xlUp
- End If
- Next i
- End With
- Set dic = Nothing
- End Sub
复制代码 |
|