|
楼主 |
发表于 2023-4-11 14:17
|
显示全部楼层
是习作代码,为交流学习,望大侠们指正,以利我提高.
- Sub 根据分数段拆分多表()
- '字典嵌套使用,对原始无序表直接处理
- Dim i, j, n, key, key1, name
- Dim arr, dic As Object
- Set dic = CreateObject("scripting.dictionary")
- Worksheets(1).Activate
- Application.DisplayAlerts = False
- For Each wks In Worksheets
- If wks.name <> ActiveSheet.name Then wks.Delete
- Next
- Application.DisplayAlerts = True
- arr = [a1].CurrentRegion
- For i = 2 To UBound(arr)
- key = Int(arr(i, 3) / 10) * 10
- If Not dic.exists(key) Then
- Set dic(key) = CreateObject("scripting.dictionary")
- End If
- key1 = arr(i, 3)
- If Not dic(key).exists(key1) Then
- dic(key)(key1) = arr(i, 1) & "," & arr(i, 2)
- Else
- dic(key)(key1) = dic(key)(key1) & "," & arr(i, 1) & "," & arr(i, 2)
- End If
- Next
- For Each 键名 In dic.keys
- Sheets.Add(after:=Sheets(Sheets.Count)).name = 键名
- [a1] = "姓名": [b1] = "分数": n = 2
- For Each 键名1 In dic(键名).keys
- name = Application.Transpose(Split(dic(键名)(键名1), ","))
- Cells(n, "A").Resize(UBound(name), 1) = name
- Cells(n, "B").Resize(UBound(name), 1) = 键名1
- n = n + 2
- Next
- Next
- Worksheets(1).Activate
- Beep
- End Sub
复制代码
|
|