|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
感谢你的回复,你的代码留待以后慢慢研究吧,我重新把我那个优化了一下,结果和你的一样。- Dim d, aa, x%, str$
- Sub zz()
- Dim i&, arr, j%, z1, r0%, j1%, y%
- i = [b65536].End(xlUp).Row
- arr = Range("b2:d" & i)
- Set d = CreateObject("Scripting.Dictionary")
- Range("g2:h100").ClearContents
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 3)) Then
- Set d(arr(i, 3)) = CreateObject("Scripting.Dictionary")
- End If
- d(arr(i, 3))(arr(i, 1)) = "(" & arr(i, 2) & ")"
- Next
- For Each aa In d("无").keys
- x = 0: str = ""
- If Not d.exists(aa) Then
- r0 = [g65536].End(xlUp).Row
- Cells(r0 + 1, "g") = aa & d("无")(aa)
- Cells(r0 + 1, "h") = 1
- Else
- Call digui(aa, 0, "", d("无")(aa))
- r0 = [g65536].End(xlUp).Row
- z1 = Split(str, ",")
- For j = 0 To UBound(z1)
- Cells(r0 + 1 + j, "g").IndentLevel = Val(Split(z1(j), "|")(1))
- Cells(r0 + 1 + j, "g") = Split(z1(j), "|")(0)
- Next
- For j = 0 To UBound(z1) - 1
- For j1 = j + 1 To UBound(z1)
- If Val(Split(z1(j1), "|")(1)) > Val(Split(z1(j), "|")(1)) Then
- y = y + 1
- Else
- Exit For
- End If
- Next
- Cells(r0 + 1 + j, "h") = y + 1: y = 0
- Next
- Cells(r0 + 1 + j, "h") = y + 1: y = 0
- End If
- Next
- End Sub
- Sub digui(Pid, n, s, w)
- Dim i&, key, temp2, sr%, sar
- If d.exists(Pid) Then
- temp2 = s & Pid & w & "|" & n & ","
- key = d(Pid).keys
- For i = 0 To UBound(key)
- Call digui(key(i), n + 1, temp2, d(Pid)(key(i)))
- Next
- Else
- If str = "" Then
- str = s & Pid & w & "|" & n
- Else
- sar = Split(s & Pid & w & "|" & n & ",", ",")
- For sr = 0 To UBound(sar)
- If InStr(str, sar(sr)) = 0 Then str = str & "," & sar(sr)
- Next
- End If
- End If
- End Sub
复制代码 |
|