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
l大~~~~非常感謝您的熱心幫忙,但小妹遇到幾個問題,是我沒說明清楚真的非常抱歉~~~~~~~
就是問題一的1:31活頁、列5:列25,還必須是第3欄為空白格才需隱藏。因為測試了一下,發現列5:列25居然全隱藏了
For i = 5 To 25
If Cells(i, 3) = "" Then
然後問題二,我把l大的程式碼插入後最後一個 End With 前(如下),但它卻連別的活頁也跟著被影響了。
最下圖是檔案的活頁,原只需排序跟隱藏1:31活頁,但修改後連月總表、週時表也跟著被隱藏了,請問是否可再幫幫小妹呢!!非常感謝~~~~~~~~
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
Sheets(i).Rows("5:25").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden =true
End With
Next
End Sub
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
Sheets(i & "").Rows("5:25").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden =true
End With
Next
End Sub
Sub 排序班別()
Dim i As Integer
Application.Calculation = xlCalculationManual '關閉自動重算, 加快速度
For i = 1 To 31
With Sheets(i & "")
.[AJ5:AJ16] = .[D5:D16].Value '將D欄公式值暫貼至AJ欄