|
本帖最后由 张小生 于 2024-9-30 22:29 编辑
详见附件,写一段代码,很长时间没写了,生疏了
- Sub mytest1()
- Application.ScreenUpdating = False
- Dim ar, dr, br(1 To 100000, 1 To 5), m, n, c, j
- Dim sortedlist As Object
- Set sortedlist = CreateObject("System.collections.sortedlist")
- dr = Sheet1.Range("a1:e1")
- ar = Sheet1.Range("b2:e17")
- For m = 1 To UBound(ar)
- sortedlist(ar(m, 1)) = ""
- Next m
- For n = 0 To sortedlist.Count - 1
- For c = 1 To UBound(ar)
- If ar(c, 1) = sortedlist.getkey(n) Then
- j = j + 1
- br(j, 1) = j
- br(j, 2) = ar(c, 1)
- br(j, 3) = ar(c, 2)
- br(j, 4) = ar(c, 3)
- br(j, 5) = ar(c, 4)
- End If
- Next c
- Set sh = Worksheets.Add(after:=Sheets(Sheets.Count))
- sh.Name = sortedlist.getkey(n)
- sh.Range("a1").Resize(1, UBound(dr, 2)) = dr
- sh.Range("a2").Resize(UBound(br), 5) = br
- Erase br
- j = 0
- Set sh = Nothing
- Next n
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|