遍历excel表排列宏

Attribute VB_Name = "模块2"
Sub 排列excel()
Attribute 排列excel.VB_ProcData.VB_Invoke_Func = " \n14"
'
' 排列excel Macro
'

'
Dim i As Long
Application.DisplayFullScreen = True
Application.EnableEvents = False
Application.ScreenUpdating = False
For i = 1 To ThisWorkbook.Sheets.Count
Sheets(i).Activate
Cells.Select
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("c2:c19"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A1:H19")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
If Abs(Sheets(i).[c19] - Sheets(i).[c2]) <= 0.001 Then
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("D2:D19"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A1:H19")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

End If

Next i
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

相关文档
最新文档