標題:
[發問]
跨工作表排序問題
[打印本頁]
作者:
msmplay
時間:
2016-4-1 04:06
標題:
跨工作表排序問題
想請教一下大師們~
以下是我用錄製巨集的方式,想要固定排序每個活頁"C6:AI14"資料,但總共有31個活頁,卻不能跨活頁同時排序
所以我必須要每個活頁做相同排序動作,以下只有錄製到第4個活頁...........
請問有簡化的寫法嗎?真的非常感謝ㄛ∼∼∼∼∼∼∼∼∼
Sub 巨集1()
Sheets("1").Select
Range("C6:AI14").Select
ActiveWorkbook.Worksheets("1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("1").Sort.SortFields.Add Key:=Range("D6:D14"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("1").Sort
.SetRange Range("C6:AI14")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("2").Select
Range("C6:AI14").Select
ActiveWorkbook.Worksheets("2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("2").Sort.SortFields.Add Key:=Range("D6:D14"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("2").Sort
.SetRange Range("C6:AI14")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("3").Select
Range("C6:AI14").Select
ActiveWorkbook.Worksheets("3").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("3").Sort.SortFields.Add Key:=Range("D6:D14"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("3").Sort
.SetRange Range("C6:AI14")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("4").Select
Range("C6:AI14").Select
ActiveWorkbook.Worksheets("4").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("4").Sort.SortFields.Add Key:=Range("D6:D14"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("4").Sort
.SetRange Range("C6:AI14")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
作者:
stillfish00
時間:
2016-4-1 09:28
回復
1#
msmplay
Sub Test()
Dim i As Integer
For i = 1 To 31
With Sheets(CStr(i))
.Sort.SortFields.Clear
.Sort.SortFields.Add key:=.Range("D6"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("C6:AI14")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Next
End Sub
複製代碼
作者:
msmplay
時間:
2016-4-1 22:13
回復
2#
stillfish00
S大~~~~~~~超級感謝!!
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)