|
本帖最后由 caiyu93 于 2023-10-16 15:08 编辑
- Sub main()
- Dim ws As Worksheet, col%, rng As Range, List As Object
- Dim i&, j%
- Set List = CreateObject("System.Collections.SortedList")
- Set ws = Sheets("sheet1")
- With ws
- Set rng = .[a1].CurrentRegion
- col = rng.Columns.Count
- arr = rng
- For i = 2 To rng.Rows.Count
- List.Add rng(i, 1).Value, Range(rng(i, 1), .Cells(i, col))
- Next
- End With
- With List
- For i = 0 To .Count - 1
- For j = 1 To col
- arr(i + 2, j) = .GetByIndex(i)(1, j)
- Next
- Next
- End With
- With Sheets("sheet2")
- Application.ScreenUpdating = 0
- .[a1].Resize(UBound(arr), UBound(arr, 2)) = arr
- Application.ScreenUpdating = 1
- End With
- End Sub
复制代码 |
|