EXCEL公式问题
答案:1 悬赏:0 手机版
解决时间 2021-11-17 11:15
- 提问者网友:浪荡绅士
- 2021-11-16 23:24
EXCEL公式问题
最佳答案
- 五星知识达人网友:由着我着迷
- 2021-11-17 00:32
附件中有个VBA写的文件,代码如下(附件直接可用!)
Sub 归类整理()
Dim da As Object, erow As Long, myrange As Range, t
Dim ary, arya, aryb, aryc, i As Long, j As Long, m As Long, s As String
t = Timer
Range("d:e") = ""
Set da = CreateObject("scripting.dictionary")
erow = Cells(Rows.Count, "A").End(3).Row
Set myrange = Range("A1:B" & erow)
ary = myrange
For i = 1 To UBound(ary, 1)
da(ary(i, 1)) = ""
Next
arya = Application.WorksheetFunction.Transpose(da.keys)
[d1].Resize(da.Count, 1) = arya
da.RemoveAll
For i = 1 To UBound(arya) "逐行遍历主索引
For j = 1 To UBound(ary) "检查源数据区A列是否是主索引
If ary(j, 1) = arya(i, 1) Then
da(ary(j, 2)) = ""
End If "此时,每个主索引的子分类及出现次数被存入字典的keys以及items
Next j
aryb = da.keys "将字典的keys存入数组
da.RemoveAll "清空数组
s = ""
For m = LBound(aryb) To UBound(aryb)
s = s & aryb(m) & "、" "字符串连接
Next
Cells(i, "e") = Left(s, Len(s) - 1) "将处理结果写入区域。
Next i
MsgBox "处理完成!共耗时" & Timer - t & "秒"
End Sub
Sub 归类整理()
Dim da As Object, erow As Long, myrange As Range, t
Dim ary, arya, aryb, aryc, i As Long, j As Long, m As Long, s As String
t = Timer
Range("d:e") = ""
Set da = CreateObject("scripting.dictionary")
erow = Cells(Rows.Count, "A").End(3).Row
Set myrange = Range("A1:B" & erow)
ary = myrange
For i = 1 To UBound(ary, 1)
da(ary(i, 1)) = ""
Next
arya = Application.WorksheetFunction.Transpose(da.keys)
[d1].Resize(da.Count, 1) = arya
da.RemoveAll
For i = 1 To UBound(arya) "逐行遍历主索引
For j = 1 To UBound(ary) "检查源数据区A列是否是主索引
If ary(j, 1) = arya(i, 1) Then
da(ary(j, 2)) = ""
End If "此时,每个主索引的子分类及出现次数被存入字典的keys以及items
Next j
aryb = da.keys "将字典的keys存入数组
da.RemoveAll "清空数组
s = ""
For m = LBound(aryb) To UBound(aryb)
s = s & aryb(m) & "、" "字符串连接
Next
Cells(i, "e") = Left(s, Len(s) - 1) "将处理结果写入区域。
Next i
MsgBox "处理完成!共耗时" & Timer - t & "秒"
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯