一个字典的问题,请高人指点下? 谢谢
时间:2011-08-11
来源:互联网
代码的作用是提取不重复数据 并统计重复了几次 之后返回到指定单元格。不过 有些不理解,
17 秒前
Sub test2()
Dim dic As Object, i%
Set dic = CreateObject("scripting.dictionary")
For i = 2 To Cells(Rows.Count, 1).End(3).Row
If dic.exists(Cells(i, 1).Value) Then dic(Cells(i, 1).Value) = dic(Cells(i, 1).Value) + 1 Else: dic(Cells(i, 1).Value) = 1
' Cells(i, 1).Value是对KEY判断么,但是后面指句dic(Cells(i, 1).Value) = 1又感觉Cells(i, 1).Value表示的是VALUE
' 不理解???
Next i
Range("e:G").Clear
Cells(1, 5).Resize(1, 2) = Array("编号", "个数")
Cells(2, 5).Resize(dic.Count, 1) = Application.Transpose(dic.keys)
'上面的代码好像都没有对KEY赋值(只是对ITEM.VALUE赋值),那么哪里来的KEYS 不理解? Cells(2, 6).Resize(dic.Count, 1) = Application.Transpose(dic.items)
Set dic = Nothing
End Sub
que.rar(12.37 KB)
17 秒前
Sub test2()
Dim dic As Object, i%
Set dic = CreateObject("scripting.dictionary")
For i = 2 To Cells(Rows.Count, 1).End(3).Row
If dic.exists(Cells(i, 1).Value) Then dic(Cells(i, 1).Value) = dic(Cells(i, 1).Value) + 1 Else: dic(Cells(i, 1).Value) = 1
' Cells(i, 1).Value是对KEY判断么,但是后面指句dic(Cells(i, 1).Value) = 1又感觉Cells(i, 1).Value表示的是VALUE
' 不理解???
Next i
Range("e:G").Clear
Cells(1, 5).Resize(1, 2) = Array("编号", "个数")
Cells(2, 5).Resize(dic.Count, 1) = Application.Transpose(dic.keys)
'上面的代码好像都没有对KEY赋值(只是对ITEM.VALUE赋值),那么哪里来的KEYS 不理解? Cells(2, 6).Resize(dic.Count, 1) = Application.Transpose(dic.items)
Set dic = Nothing
End Sub
附件

2011-8-11 19:30, 下载次数: 2
作者: andrewyang 发布时间: 2011-08-11
这个看蓝版那个字典的帖子就好了吧,有详解。。。
作者: jiminyanyan 发布时间: 2011-08-11
做个记号

作者: 学以用之 发布时间: 2011-08-11
If dic.exists(Cells(i, 1).Value) Then dic(Cells(i, 1).Value) = dic(Cells(i, 1).Value) + 1 Else: dic(Cells(i, 1).Value) = 1
如果存在Cells(i, 1).Value这个KEY,则item累加,否则赋初始值
dic(Cells(i, 1).Value) = 1 这句赋KEY为Cells(i, 1).Value,ITEM为1
如果存在Cells(i, 1).Value这个KEY,则item累加,否则赋初始值
dic(Cells(i, 1).Value) = 1 这句赋KEY为Cells(i, 1).Value,ITEM为1
作者: doitbest 发布时间: 2011-08-11
If dic.exists(Cells(i, 1).Value) Then
dic(Cells(i, 1).Value) = dic(Cells(i, 1).Value) + 1
Else
dic(Cells(i, 1).Value) = 1
这个应该知道
dic(Cells(i, 1).Value) = dic(Cells(i, 1).Value) + 1
Else
dic(Cells(i, 1).Value) = 1
这个应该知道
作者: wj2368 发布时间: 2011-08-11
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28