数组排序——VBA工作簿排序

Sub OrderBy()
    Dim SheetCount As Long
    SheetCount = ThisWorkbook.Worksheets.Count - 1
    ReDim SheetNameArray(SheetCount)
    Dim Index As Long
    Dim Names As String
    For Index = 0 To SheetCount
        SheetNameArray(Index) = ThisWorkbook.Sheets(Index + 1).Name
    Next
    
    Dim CacheIndex As Long
    Dim Cache As String
    For Index = 0 To SheetCount - 1
        For CacheIndex = Index + 1 To SheetCount
            If SheetNameArray(Index) > SheetNameArray(CacheIndex) Then
                Cache = SheetNameArray(Index)
                SheetNameArray(Index) = SheetNameArray(CacheIndex)
                SheetNameArray(CacheIndex) = Cache
            End If
        Next
    Next
    For Index = 0 To SheetCount
        ThisWorkbook.Worksheets(SheetNameArray(Index)).Move after:=ThisWorkbook.Worksheets(Index + 1)
    Next
    
End Sub

 

展开阅读全文

没有更多推荐了,返回首页