|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
蓝桥玄霜 发表于 2010-10-18 12:52
[/code]实例5 前期绑定的字典实例
一、问题的提出:
有多列多行数据,其中有重复的行,要求编写一段代码 ...
我进行了一下改写,一次循环完成:
Sub test()
Dim d As Object, a, b, j&
Dim ss As String, n&
Me.UsedRange.Offset(3, 0) = ""
a = Sheet1.Range(Sheet1.[a4], Sheet1.[i65536].End(xlUp))
Set d = CreateObject("scripting.dictionary")
ReDim b(1 To UBound(a), 1 To 8)
For i = 1 To UBound(a)
ss = a(i, 1) & a(i, 2) & a(i, 4) & a(i, 5) & a(i, 6) & a(i, 8)
If Not d.Exists(ss) Then
n = n + 1
d(ss) = n
b(n, 1) = a(i, 2): b(n, 2) = a(i, 5): b(n, 3) = a(i, 6): b(n, 4) = a(i, 4)
b(n, 5) = a(i, 1): b(n, 6) = a(i, 8): b(n, 7) = a(i, 9): b(n, 8) = a(i, 9) * b(n, 5) * b(n, 6) / 100
Else
b(d(ss), 7) = b(d(ss), 7) & "+" & a(i, 9)
b(d(ss), 8) = b(d(ss), 8) + a(i, 9) * b(n, 5) * b(n, 6) / 100
End If
Next
[b4].Resize(n, 8) = b
End Sub |
|