|
分块处理。。。- Sub ykcbf() '//2024.8.19
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("数据源")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 6)
- End With
- For i = 2 To UBound(arr)
- s = arr(i, 3)
- If Not d.exists(s) Then
- d(s) = Array(i, i)
- Else
- t = d(s)
- t(1) = i
- d(s) = t
- End If
- Next
- With Sheets("期望")
- .UsedRange.Offset(1).ClearContents
- m = 1
- For Each k In d.keys
- r1 = d(k)(0): r2 = d(k)(1)
- n = r2 - r1 + 1
- n = IIf(n > 10, 10, n)
- For i = r1 To r1 + n - 1
- m = m + 1
- For j = 1 To UBound(arr, 2)
- .Cells(m, j) = arr(i, j)
- Next
- Next
- m = m + 1
- r = .Cells(Rows.Count, 1).End(3).Row
- Set Rng = .Cells(r - n + 1, 1).Resize(n, 6)
- Rng.Sort Rng.Columns(5), 2
- Next
- End With
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
|
|