发布网友 发布时间:2022-02-20 06:18
共1个回答
热心网友 时间:2022-02-20 08:04
工作表本身并无排序功能,不过可以使用vba编程实现,就是麻烦点。
以下是之家那里抄袭来的宏,你可以试试(适合数字工作表名称排序):
Sub Sortsheets()
Dim sheetName()
Dim sheetcount As Integer
Dim i As Integer
Dim oldactive As Object
On Error Resume Next
sheetcount = ActiveWorkbook.Sheets.Count
If Err <> 0 Then Exit Sub
If ActiveWorkbook.ProtectStructure Then
MsgBox ActiveWorkbook.Name
Exit Sub
End If
Application.EnableCancelKey = xlDisabled
sheetcount = ActiveWorkbook.Sheets.Count
ReDim sheetName(1 To sheetcount)
Set oldactive = ActiveSheet
For i = 1 To sheetcount
sheetName(i) = ActiveWorkbook.Sheets(i).Name
Next i
Call bubblesort(sheetName)
Application.ScreenUpdating = False
'Òƶ¯¹¤×÷±í
For i = 1 To sheetcount
ActiveWorkbook.Sheets(sheetName(i)).Move ActiveWorkbook.Sheets(i)
Next i
oldactive.Activate
End Sub
Sub bubblesort(List())
Dim first As Integer, Last As Integer
Dim i As Integer, j As Integer
Dim temp
first = LBound(List)
Last = UBound(List)
For i = first To Last - l
For j = i + 1 To Last
If UCase(List(i)) > UCase(List(j)) Then
temp = List(j)
List(j) = List(i)
List(i) = temp
End If
Next j
Next i
End Sub