+ Reply to Thread
Results 1 to 4 of 4

Sort Worksheets with numbered sheets first and text sheets last

  1. #1
    Registered User
    Join Date
    10-30-2007
    Posts
    13

    Sort Worksheets with numbered sheets first and text sheets last

    I need a Macro to sort all sheets in a workbook by name that puts numbered (i.e. 6,7,8,9,10) first and then text names last. (i.e. "Samples", "Content") So it would look like 6,7,8,9,10,20,115,Content, Samples.

    Here is what I have so far that does the numbered sheets correctly but puts the text named sheets first.

    Sub WorksheetsSortAscending()
    ' sort worksheets in a workbook in ascending order
    Dim sCount As Integer, i As Integer, j As Integer
    sCount = Worksheets.Count
    If sCount = 1 Then Exit Sub
    For i = 1 To sCount - 1
    For j = i + 1 To sCount
    If Val(Worksheets(j).Name) < Val(Worksheets(i).Name) Then
    Worksheets(j).Move before:=Worksheets(i)
    End If
    Next j
    Next i
    End Sub

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,046

    Re: Sort Worksheets with numbered sheets first and text sheets last

    Try:

    Please Login or Register  to view this content.
    Last edited by Mumps1; 01-03-2013 at 03:28 PM.

  3. #3
    Registered User
    Join Date
    10-30-2007
    Posts
    13

    Re: Sort Worksheets with numbered sheets first and text sheets last

    Quote Originally Posted by Mumps1 View Post
    Try:

    Please Login or Register  to view this content.
    That errors (out of range) when it gets to "ActiveWorkbook.Sheets(ShtName).Move Before:=ActiveWorkbook.Sheets(1)"

    It does begin to resort them though I cant really tell how it was going to do it.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,046

    Re: Sort Worksheets with numbered sheets first and text sheets last

    Could you post your file?
    Last edited by Mumps1; 01-03-2013 at 04:42 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1