|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 duquancai 于 2018-7-29 13:40 编辑
- Sub main()
- Dim a, js As Object, j$, d As Object, b(), k, t, s
- a = Range("a2:d" & Cells(Rows.Count, 2).End(3).Row)
- Set d = CreateObject("Scripting.Dictionary")
- For i = 1 To UBound(a)
- If Len(a(i, 1)) * Len(a(i, 2)) Then d(a(i, 1) & "|" & a(i, 2)) = d(a(i, 1) & "|" & a(i, 2)) & "," & i
- Next
- k = d.keys: t = d.items: ReDim b(1 To UBound(k) + 1, 1 To UBound(a, 2))
- Set js = CreateObject("MSScriptControl.ScriptControl")
- js.Language = "JavaScript"
- For i = 0 To UBound(k)
- s = Split(k(i), "|"): r = Split(Mid(t(i), 2), ","): s1 = Empty: s2 = Empty
- For Each x In r
- s1 = s1 & "," & a(x, 3): s2 = s2 & "," & a(x, 4)
- Next
- s1 = Mid(s1, 2): s2 = Mid(s2, 2): b(i + 1, 1) = s(0): b(i + 1, 2) = s(1)
- j = "a='',b='',o={},q={};'" & s1 & "'.replace(/[^,]+/g,function(s){o[s]=1;});"
- j = j & "'" & s2 & "'.replace(/[^,]+/g,function(s){q[s]=1;});"
- j = j & "for(k in o)a?a+=';'+k:a=k;for(k in q)b?b+=';'+k:b=k;"
- b(i + 1, 3) = js.eval(j & "a;")
- b(i + 1, 4) = js.eval(j & "b;")
- Next
- Range("f2:j100").ClearContents
- Range("f2").Resize(i, UBound(a, 2)) = b
- End Sub
复制代码 |
|