EXCEL 排序工作列 === ###### tags: `Excel` 參考: [如何在Excel中按字母/字母數字順序對工作表進行排序?](https://zh-tw.extendoffice.com/documents/excel/629-excel-sort-sheets.html) 1. 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。 2. 點擊 插入 > 模塊,然後將以下宏粘貼到 模塊窗口. 3. 按 F5 運行此宏的鍵。 在以下提示框中,單擊 是,所有工作表將按字母升序排序; 然後點擊 沒有,所有工作表將按字母降序排序。 ```vb= Sub SortWorkBook() Dim xResult As VbMsgBoxResult xTitleId = "KutoolsforExcel" xResult = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) & "Clicking No will sort in Descending Order", vbYesNoCancel + vbQuestion + vbDefaultButton1, xTitleId) For i = 1 To Application.Sheets.Count For j = 1 To Application.Sheets.Count - 1 If xResult = vbYes Then If UCase$(Application.Sheets(j).Name) > UCase$(Application.Sheets(j + 1).Name) Then Sheets(j).Move after:=Sheets(j + 1) End If ElseIf xResult = vbNo Then If UCase$(Application.Sheets(j).Name) < UCase$(Application.Sheets(j + 1).Name) Then Application.Sheets(j).Move after:=Application.Sheets(j + 1) End If End If Next Next End Sub ```