用于在工作簿中重命名和排序工作表的Excel宏?

问题描述 投票:-2回答:1

我必须在工作簿中重命名大约200 excel表,并且还需要对它们进行排序。任何人都知道这个宏。提前致谢。

excel
1个回答
1
投票

用它来分类

Sub SortWorkBook()
    Dim xResult As VbMsgBoxResult
   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

用于重命名

Sub RenamingSheets()
nmbr = InputBox("enter first number(enter only number) ", "Renaming Sheets")
For ws = 1 To Worksheets.Count
Sheets(ws).Name = "SheetName" & nmbr
nmbr = nmbr + 1
Next ws
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.