EXCEL按SHEET排序 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

  再任意一个工作表名称点右键,点查看源代码,把下面代码复制过去执行

  Sub Sort_Sheets()

  Dim sCount As Integer, I As Integer, R As Integer

  ReDim Na(0) As String

  sCount = Sheets.Count

  For I = 1 To sCount

  ReDim Preserve Na(I) As String

  Na(I) = Sheets(I).Name

  Next

  For I = 1 To sCount - 1

  For R = I + 1 To sCount

  If Na(R) Na(I) Then

  JH = Na(I)

  Na(I) = Na(R)

  Na(R) = JH

  End If

  Next

  Next

  For I = 1 To sCount

  Sheets(Na(I)).Move After:=Sheets(I)

  Next

  End Sub

  excel 根据sheet名排序

  随便点一个sheet,查看代码Sub 按字母排序工作表()If MsgBox(真的要按工作表名称首字拼音的顺序(A~Z)来排序工作表吗?, vbYesNo, 请确认此次替换) = vbYes ThenDim wbook As Workbook, wsheet As Worksheet, i As Integer, countsh As Integer, ss() As StringSet wbook = ActiveWorkbook

  countsh = wbook.Sheets.Count

  ReDim ss(1 To countsh)

  For i = 1 To countsh

  ss(i) = wbook.Sheets(i).Name

  Next

  Set wsheet = wbook.Worksheets.Add

  For i = 1 To countsh

  wsheet.Cells(i, 1).Value = ss(i)

  Next

  wsheet.Columns(1).Sort Key1:=wsheet.Columns(1), Order1:=xlAscending

  For i = 1 To countsh

  ss(i) = wsheet.Cells(i, 1).Value

  Next

  Application.DisplayAlerts = False

  wsheet.Delete

  Application.DisplayAlerts = True

  For i = 1 To countsh

  wbook.Sheets(ss(i)).Move after:=wbook.Sheets(countsh)

  NextElse: MsgBox 用户取消了此次排序操作!

  End If

  End Sub执行搞定,^_^

  还有个word里的,硬回车替换软回车^l替换^p

最新文章