|
- Sub 测试() ''答题专用套路--by:学习使我快乐
- Dim i, j, k, m, n, arr, brr, crr, drr
- Dim sht As Worksheet, wbk As Workbook, rng As Range
- Dim dic As Object, key As String, keys, items
- Set dic = CreateObject("scripting.dictionary")
- arr = Sheet4.Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- key = arr(i, 1)
- dic(key) = dic(key) & "," & i
- Next
- keys = dic.keys
- items = dic.items
- For i = LBound(keys) To UBound(keys)
- Cells(2 + i, "G") = "'" & keys(i)
- Cells(2 + i, "H").Resize(1, 3) = 合并(items(i), arr)
- Next
- Set rng = Range("G1").CurrentRegion
- rng.Sort key1:=rng.Range("A1"), order1:=xlAscending, Header:=xlYes
- End Sub
- Function 合并(items, arr)
- Dim i, brr, s1, s2, s3, 原始行号
- Dim dic1 As Object
- Set dic1 = CreateObject("scripting.dictionary")
- Dim dic2 As Object
- Set dic2 = CreateObject("scripting.dictionary")
- Dim dic3 As Object
- Set dic3 = CreateObject("scripting.dictionary")
- brr = Split(items, ",")
- For i = 1 To UBound(brr)
- 原始行号 = brr(i)
- dic1(arr(原始行号, 3)) = dic1(arr(原始行号, 3)) + 1
- dic2(arr(原始行号, 4)) = dic2(arr(原始行号, 4)) + 1
- dic3(arr(原始行号, 5)) = dic3(arr(原始行号, 5)) + 1
- Next
- For i = 1 To dic1.Count
- s1 = s1 & "-" & dic1.keys()(i - 1) & dic1.items()(i - 1)
- Next
- For i = 1 To dic2.Count
- s2 = s2 & "-" & dic2.keys()(i - 1) & dic2.items()(i - 1)
- Next
- For i = 1 To dic3.Count
- s3 = s3 & "-" & dic3.keys()(i - 1) & dic3.items()(i - 1)
- Next
- ReDim crr(1 To 3)
- crr(1) = Mid(s1, 2)
- crr(2) = Mid(s2, 2)
- crr(3) = Mid(s3, 2)
- 合并 = crr
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|