|
jinball 发表于 2014-1-7 16:16
已经重新说明了,在Sheet2-Sheet8中有说明,谢谢版主!
改为一个通用程序,各个工作表调用它:- Sub Main(s$)
- Dim a, arr, brr(1 To 1000, 0 To 10), i&, j&, m&, sh As Worksheet, lc%, f As Boolean
- Application.ScreenUpdating = False
- lc = Sheets("Sheet1").Range("a1").CurrentRegion.Columns.Count
- a = Split(s, ":")
- If UCase(a(0)) = "P" Then
- char = a(1)
- Else
- char = a(0)
- f = True
- End If
- 列号 = GetColumn(char)
- Set sh = ActiveSheet
- 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, lc).Sort Key1:=.Cells(i, 列号), Order1:=1, Header:=xlNo
- arr = .Cells(i, 16).Resize(10)
- If f Then
- brr(m, 0) = UCase(a(0)) & i & ":P" & i + 9
- Else
- brr(m, 0) = "P" & i & ":" & UCase(a(1)) & i + 9
- End If
- For j = 1 To 10
- brr(m, j) = arr(j, 1)
- .Cells(i + j - 1, 16).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
- Function GetColumn(char)
- Dim t
- On Error Resume Next
- t = Columns(char & ":" & char).Column
- If Err.Number <> 0 Then GetColumn = "超出范围" Else GetColumn = t
- End Function
复制代码 |
|