|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
以下代码中,直接用用变量时不能计算正确结果,而在变量前增加字符可以计算正确结果,不知道哪边出了问题,谢谢
Sub test()
'**********直接变量
Dim dic As Object, arr
Set dic = CreateObject("scripting.dictionary")
For i = 1 To Sheet1.[a65535].End(xlUp).Row
dic(Cells(i, 1)) = dic(Cells(i, 1)) + Cells(i, 2)
Debug.Print Join(dic.keys, ",")
Next
arr = WorksheetFunction.Transpose(dic.keys)
[c1].Resize(UBound(arr), 1) = arr
arr = WorksheetFunction.Transpose(dic.Items)
[d1].Resize(UBound(arr), 1) = arr
Set dic = Nothing
'变量前加字符
Set dic = CreateObject("scripting.dictionary")
For i = 1 To Sheet1.[a65535].End(xlUp).Row
dic("a" & Cells(i, 1)) = dic("a" & Cells(i, 1)) + Cells(i, 2)
Debug.Print Join(dic.keys, ",")
Next
arr = WorksheetFunction.Transpose(dic.keys)
[e1].Resize(UBound(arr), 1) = arr
arr = WorksheetFunction.Transpose(dic.Items)
[f1].Resize(UBound(arr), 1) = arr
End Sub
直接用变量效果 前面加a字符效果
A01 aA01 12
A01 1 aB02 15
B02 aC03 18
B02 2
C03
C03 3
A01
A01 4
B02
B02 5
C03
C03 6
A01
A01 7
B02
B02 8
C03
C03 9
[ 本帖最后由 zhufree 于 2010-10-25 16:19 编辑 ] |
|