|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Sub Demo()
- Dim objDic As Object, objDic2 As Object, rngData As Range
- Dim i As Long, sKey, arrRes, aTxt, arrData
- Set objDic = CreateObject("scripting.dictionary")
- Set objDic2 = CreateObject("scripting.dictionary")
- Set rngData = Range("A1").CurrentRegion
- arrData = rngData.Value
- For i = LBound(arrData) + 1 To UBound(arrData)
- sKey = arrData(i, 2) & "|" & arrData(i, 3)
- If objDic.exists(sKey) Then
- objDic(sKey) = objDic(sKey) + arrData(i, 7)
- objDic2(sKey) = objDic2(sKey) & "|" & arrData(i, 6)
- Else
- objDic(sKey) = arrData(i, 7)
- objDic2(sKey) = arrData(i, 6)
- End If
- Next i
- ReDim arrRes(1 To objDic.Count, 1 To UBound(arrData, 2))
- i = 0
- For Each sKey In objDic.Keys
- i = i + 1
- arrRes(i, 1) = i
- aTxt = Split(sKey, "|")
- arrRes(i, 2) = aTxt(0)
- arrRes(i, 3) = aTxt(1)
- arrRes(i, 4) = UBound(Split(objDic2(sKey), "|")) + 1
- arrRes(i, 5) = objDic2(sKey)
- arrRes(i, 7) = objDic(sKey)
- arrRes(i, 8) = "台"
- Next
- rngData.Rows(1).Copy [S1]
- Range("S2").Resize(objDic.Count, UBound(arrData, 2)).Value = arrRes
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|