|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
jinball 发表于 2014-1-7 15:24
版主,是这样的,这个表格我是用来做统计的,因为Sheet1中的数据是不断添加的,那么每次添加我都要重新依 ...
排序功能对原数据产生了干扰,改为复制Sheet1,仅对副本排序,缺点速度慢:
- Sub Sheet2()
- Dim arr, brr(1 To 1000, 0 To 10), i&, j&, m&, sh As Worksheet
- Application.ScreenUpdating = False
- Set sh = Sheets("Sheet2")
- sh.Cells.Clear
- Sheets("Sheet1").Copy
- With ActiveSheet
- For i = 1 To Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row Step 10
- m = m + 1
- .Cells(i, 1).Resize(10, 13).Sort Key1:=.Cells(i, 9), Order1:=1, Header:=xlNo
- arr = .Cells(i, 12).Resize(10)
- brr(m, 0) = "I" & i & ":L" & i + 9
- For j = 1 To 10
- brr(m, j) = arr(j, 1)
- .Cells(i + j - 1, 12).Copy
- sh.Cells(m, j + 1).PasteSpecial Paste:=xlPasteFormats
- Next
- Next
- End With
- ActiveWorkbook.Close False
- sh.[a1].Resize(m, 11) = brr
- Application.ScreenUpdating = True
- End Sub
- Sub Sheet3()
- Dim arr, brr(1 To 1000, 0 To 10), i&, j&, m&, sh As Worksheet
- Application.ScreenUpdating = False
- Set sh = Sheets("Sheet3")
- sh.Cells.Clear
- Sheets("Sheet1").Copy
- With ActiveSheet
- For i = 1 To Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row Step 10
- m = m + 1
- .Cells(i, 1).Resize(10, 13).Sort Key1:=.Cells(i, 10), Order1:=1, Header:=xlNo
- arr = .Cells(i, 12).Resize(10)
- brr(m, 0) = "J" & i & ":L" & i + 9
- For j = 1 To 10
- brr(m, j) = arr(j, 1)
- .Cells(i + j - 1, 12).Copy
- sh.Cells(m, j + 1).PasteSpecial Paste:=xlPasteFormats
- Next
- Next
- End With
- ActiveWorkbook.Close False
- sh.[a1].Resize(m, 11) = brr
- Application.ScreenUpdating = True
- End Sub
- Sub Sheet4()
- Dim arr, brr(1 To 1000, 0 To 10), i&, j&, m&, sh As Worksheet
- Application.ScreenUpdating = False
- Set sh = Sheets("Sheet4")
- sh.Cells.Clear
- Sheets("Sheet1").Copy
- With ActiveSheet
- For i = 1 To Sheets("Sheet1").Range("a" & Rows.Count).End(xlUp).Row Step 10
- m = m + 1
- .Cells(i, 1).Resize(10, 13).Sort Key1:=.Cells(i, 11), Order1:=1, Header:=xlNo
- arr = .Cells(i, 12).Resize(10)
- brr(m, 0) = "K" & i & ":L" & i + 9
- For j = 1 To 10
- brr(m, j) = arr(j, 1)
- .Cells(i + j - 1, 12).Copy
- sh.Cells(m, j + 1).PasteSpecial Paste:=xlPasteFormats
- Next
- Next
- End With
- ActiveWorkbook.Close False
- sh.[a1].Resize(m, 11) = brr
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|