|
代码已更新。。。
- Sub ykcbf() '//2024.4.14
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("分组表")
- r = .Cells(Rows.Count, 1).End(3).Row
- Set Rng = .[b3].Resize(r - 2, 5)
- With Rng
- .Parent.Sort.SortFields.Clear
- .Sort Key1:=.Item(4), Order1:=1, Key2:=.Item(5), Order2:=1, Header:=2
- End With
- st = Application.InputBox("请输入分组起始编号:", "分组编号", "101")
- If st = Empty Then Exit Sub
- arr = .[a1].Resize(r, 9)
- On Error Resume Next
- For i = 3 To UBound(arr)
- s = arr(i, 5) & arr(i, 6)
- If s <> Empty Then
- d(s) = d(s) + 1
- If Not d1.exists(s) Then
- d1(s) = i
- End If
- End If
- Next
- For Each k In d.keys
- n = n + 1
- m = 0
- For i = 3 To UBound(arr)
- s = arr(i, 5) & arr(i, 6)
- If s = k Then
- For x = 1 To d(s)
- m = m + 1
- x = m Mod 20
- .Cells(d1(s) + m - 1, 7) = Val(st) + n - 1
- .Cells(d1(s) + m - 1, 8) = IIf(x = 0, 20, x)
- If m = d(s) Then Exit For
- Next
- End If
- i = i + d(s) - 1
- Next
- Next
- End With
- MsgBox "OK!"
- End Sub
复制代码
|
|