|
本帖最后由 eikok 于 2014-5-19 15:42 编辑
求教对一个工作簿中的所有工作表都按照班级升序?
Sub 宏3()
Columns("B:E").Select
ActiveWorkbook.Worksheets("高2文").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("高2文").Sort.SortFields.Add Key:=Range("E2:E1229"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("高2文").Sort
.SetRange Range("B1:E1229")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
E列是班级列
- Sub 宏3()
- Dim sht As Worksheet, lCol&
- Application.ScreenUpdating = False
- For Each sht In Worksheets
- With sht
- lCol = .Cells(Rows.Count, "e").End(xlUp).Row
- With .Sort.SortFields
- .Clear
- .Add Key:=sht.Range("e2:e" & lCol), _
- SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
- End With
- With .Sort
- .SetRange sht.Range("b1:e" & lCol)
- .Header = xlYes
- .MatchCase = False
- .Orientation = xlTopToBottom
- .SortMethod = xlPinYin
- .Apply
- End With
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "排序完成"
- End Sub
复制代码
|
|