|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
明白了,一级科目编码(4位)和二级科目编码在一列中,必须分开:- Sub Macro1()
- Dim d As Object, ds As Object, sh As Worksheet, a, arr, brr, i&, j&, l&, s$, t, temp$
- Set d = CreateObject("scripting.dictionary")
- arr = Sheets("原始数据").Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- If Len(arr(i, 2)) Then
- If Not d.Exists(arr(i, 2)) Then Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- If Len(arr(i, 3)) = 4 Then
- d(arr(i, 2))(arr(i, 4)) = d(arr(i, 2))(arr(i, 4)) & "," & i
- temp = arr(i, 4)
- Else
- d(arr(i, 2))(temp & arr(i, 4)) = d(arr(i, 2))(temp & arr(i, 4)) & "," & i
- End If
- End If
- Next
- k = d.Keys
- On Error Resume Next
- For l = 0 To d.Count - 1
- Set sh = Sheets(k(l))
- If Not sh Is Nothing Then
- Set ds = d(k(l))
- With sh.Range("A3").CurrentRegion
- .Offset(1, 3).ClearContents
- brr = .Value
- For i = 2 To UBound(brr)
- If Len(brr(i, 1)) Then
- s = brr(i, 1)
- temp = s
- Else
- s = temp & brr(i, 3)
- End If
- t = ds(s)
- If t <> "" Then
- a = Split(t, ",")
- For j = 1 To UBound(a)
- brr(i, arr(a(j), 1) + 3) = arr(a(j), 7)
- Next
- End If
- Next
- .Value = brr
- End With
- End If
- Next
- End Sub
复制代码 |
|