|
本帖最后由 kisses88 于 2014-12-4 15:42 编辑
问题二.zip
(7.48 KB, 下载次数: 4)
之前曾经在版主帮忙下解决掉的问题有了进阶版,烦请各位达人看看应该如何解决。万分感激。
大家可参考之前的帖子。
http://club.excelhome.net/thread-1092153-1-1.html
下面是以前的代码,不知是否可以修改一下来实现现在这个问题?但我自己真不知道该怎么改。T O T
- Sub Macro1()
- Dim arr, brr(), i&, j&, v&, m#, k, t, k2, t2, s$, d As Object, ds As Object
- Set d = CreateObject("scripting.dictionary")
- Set ds = CreateObject("scripting.dictionary")
- arr = Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- If Not d.Exists(arr(i, 1)) Then Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- d(arr(i, 1))(arr(i, 2)) = d(arr(i, 1))(arr(i, 2)) + arr(i, 3)
- ds(arr(i, 1)) = ds(arr(i, 1)) + arr(i, 3)
- Next
- k = d.keys
- t = ds.items
- ReDim brr(0 To d.Count - 1, 1 To 2)
- With WorksheetFunction
- For i = 0 To d.Count - 1
- brr(i, 1) = k(i)
- k2 = d(k(i)).keys
- t2 = d(k(i)).items
- m = .Max(t2)
- v = .Match(m, t2, 0) - 1
- s = k2(v)
- brr(i, 2) = s
- If t(i) <> 0 Then brr(i, 2) = brr(i, 2) & Format(m / t(i), "0%") & Chr(10)
- For j = 0 To UBound(t2)
- If j <> v Then brr(i, 2) = brr(i, 2) & "/" & k2(j)
- Next
- Next
- End With
- [k10].Resize(d.Count, 2) = brr
- End Sub
复制代码
|
|