|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
鄂龙蒙 发表于 2014-5-29 10:54
基本达到目的了,谢谢!
将单号在月份后面显示,怎么增加一级呢?再次谢谢!
已经修改- Private Sub UserForm_Initialize()
- Dim nodex As Node
- Dim rng As Range
- Dim brr(), crr, arr
- Dim aa, bb, i&, d, r
- Dim rootnode
- Dim tmp As String
- Dim tmpmonth As String
- Dim mrr
- Dim itemarr
- Set d = CreateObject("scripting.dictionary")
- Set dm = CreateObject("scripting.dictionary")
- Sheet1.Activate '激活表1
- With TreeView1 '设置TreeView控件属性
- .Nodes.Clear
- .Style = 6
- .LineStyle = 1
- Set d = CreateObject("Scripting.Dictionary")
- With Worksheets("明细统计表")
- r = .Cells(.Rows.Count, 4).End(xlUp).Row
- Set rng = .Range("D4:E" & r)
- crr = rng
- ReDim brr(1 To UBound(crr), 1 To 3)
- '//分解日期
- For i = 1 To UBound(crr)
- brr(i, 1) = Split(crr(i, 2), "/")(0) '//年
- brr(i, 2) = Format(Split(crr(i, 2), "/")(1), "00") '//月
- brr(i, 3) = crr(i, 1)
- Next i
- '//放入字典
- For i = 1 To UBound(brr) '删除重复号码
- If brr(i, 1) <> "" Then '删除空行
- d(brr(i, 1)) = d(brr(i, 1)) & "|" & brr(i, 2) & "," & brr(i, 3)
- End If
- Next
- End With
- .Nodes.Clear
- Dim tmpmonths As String
- Dim dannumber As String
- Set nodex = .Nodes.Add(, , "年度", "年度") '添加根节点
- For Each rootnode In myarrs(d.keys)
- m = m + 1
- tmp = CStr(rootnode) & "年"
- Debug.Print rootnode
- Set nodex = .Nodes.Add("年度", tvwChild, Key:=tmp, Text:=tmp) '添加二级节点 年份
- '
- mrr = Split(d(rootnode), "|")
- For k = 1 To UBound(mrr)
- tmpmonths = Split(mrr(k), ",")(0) '//月
- dannumber = Split(mrr(k), ",")(1) '//单号
- dm(tmpmonths) = dm(tmpmonths) & "|" & dannumber
-
- Next
- mrr = myarrs(dm.keys)
- '// itemarr = myarrs(dm.items)
- Dim l As Integer
- n = 0
- For k = 0 To UBound(mrr)
- tmpmonth = mrr(k) & "月"
- Debug.Print tmpmonth
- Set nodex = .Nodes.Add(tmp, tvwChild, rootnode & tmpmonth, tmpmonth) '添加三级节点 月份
- Debug.Print dm(mrr(k))
- itemarr = myarrs(Split(dm(mrr(k)), "|"))
- For l = 1 To UBound(itemarr)
- n = n + 1
- Set nodex = .Nodes.Add(rootnode & tmpmonth, tvwChild, rootnode & tmpmonth & itemarr(l) & n, itemarr(l))
- Next
- '//key 不可以重复 ?
- '//不在不同分支都不可以??
- Next
- dm.RemoveAll
- Next
- '// Set d = Nothing
- End With
- End Sub
- Function myarrs(tmparr)
- Dim tmp As Variant
- For i = 0 To UBound(tmparr) - 1
- For j = 0 To UBound(tmparr) - (i + 1)
- If tmparr(j) > tmparr(j + 1) Then
- tmp = tmparr(j): tmparr(j) = tmparr(j + 1): tmparr(j + 1) = tmp
- End If
- Next j
- Next i
- myarrs = tmparr
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|