|
Sub test() '少量字典 + 数组
Dim d As Object, ar&(), br, r&, c%, y&, x%
Set d = CreateObject("scripting.dictionary")
br = [j1:r6]
ReDim ar&(1 To UBound(br) - 1, 1 To UBound(br, 2) - 1) '长整型数组,初始赋值为0
For r = 2 To UBound(br)
d(br(r, 1)) = r - 1
Next
For c = 2 To UBound(br, 2)
d(br(1, c)) = c - 1
Next
'以上少量字典只记录索引号,也就是相关数据累加位置,数据的处理还是交给数组去做吧
br = [a1].CurrentRegion.Resize(, 7)
For r = 2 To UBound(br)
If d.exists(br(r, 1)) Then
y = d(br(r, 1)) '读取索引号(行位置)
For c = 2 To UBound(br, 2) Step 2
If d.exists(br(r, c)) Then
x = d(br(r, c)) '读取索引号(列位置)
ar(y, x) = ar(y, x) + br(r, c + 1) '相关位置累加汇总
End If
Next
End If
Next
[k2].Resize(UBound(ar), UBound(ar, 2)) = ar '写入数组
Set d = Nothing
End Sub |
|