|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
回复 1楼 彭希仁 的帖子
Sub MyT()
Dim t
t = Timer
Dim arr, ara
Dim d As New Dictionary
Dim i As Integer, j As Integer, x As Integer, y As Integer
arr = Sheet1.Range("B1").CurrentRegion '把汇总表赋值给数组arr
For i = 4 To UBound(arr)
If Len(arr(i, 1)) = 0 Then arr(i, 1) = arr(i - 1, 1)
Next i
For i = 3 To UBound(arr, 2)
If Len(arr(2, i)) = 0 Then arr(2, i) = arr(2, i - 1)
Next i
'以上两个小循环意为去除合并单元格的后遗症
For j = 2 To Sheets.Count '循环总表外的其它工作表
ara = Sheets(j).Range("B1").CurrentRegion '将子工作表i赋值给数据ara
For i = 4 To UBound(ara)
If Len(ara(i, 1)) = 0 Then ara(i, 1) = ara(i - 1, 1)
Next i
For i = 3 To UBound(ara, 2)
If Len(ara(2, i)) = 0 Then ara(2, i) = ara(2, i - 1)
Next i
'以上两小循环也是同上(去除合并单元格的后遗症)
Dim mystr As String
For y = 3 To UBound(ara, 2)
For x = 4 To UBound(ara)
mystr = ara(x, 1) & "|" & ara(x, 2) & "|" & ara(2, y) & "|" & ara(3, y)
d(mystr) = d(mystr) + ara(x, y)
Next x
Next y
'将mystr即四个条件下的数值进行累加并写入数组
Erase ara '这个释放好像写不写都无所谓(好习惯,还是写上^_^)
Next j
'Stop'边写边调试
For y = 3 To UBound(arr, 2)
For x = 4 To UBound(arr)
mystr = arr(x, 1) & "|" & arr(x, 2) & "|" & arr(2, y) & "|" & arr(3, y)
arr(x, y) = d(mystr)
Next x
Next y
'在总表数组里进行字典对应填充(即四个条件符合者)
'Stop'边写边调试
Sheet1.Range("B1").CurrentRegion = arr '赋值出来给总表
'Stop'边写边调试
MsgBox Timer - t
End Sub
这样不知道对不对,,,,如果对了,好像就也不是太难....偶只是菜鸟(PS:字典我是直接添加引用scrrun.dll)
补充一下,如果再多几个条件的话,切记要改这里 mystr = ara(x, 1) & "|" & ara(x, 2) & "|" & ara(2, y) & "|" & ara(3, y)........
[ 本帖最后由 fssunnymen 于 2010-2-3 18:13 编辑 ] |
|