Results 1 to 12 of 12

Thread: Putting the worksheets in order...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    VBAX Contributor Daxton A.'s Avatar
    Joined
    Jun 2004
    Location
    Biloxi, Mississippi
    Posts
    143
    Location

    Yea It's working

    I looked at it and figured out that I can just use the sub for sorting the sheets that I already have in there. LOL. This question was before i knew that once a workbook is sorted and saved, u can't go back to the way it was before. Like the way they were b4 the order of the worksheets changed. Once that was told to me, I just used the Module that I already had written. But Thank You, All of you that responded.

    Here's my code to see if I have anything that could be changed.

    Sub SortSheetsAscending()
    ' Macro1 Macro
    ' Macro recorded 1/9/03 by Daxton Allen
    Dim theFlag As Integer
    Dim sheet1 As String
    Dim Sheet2 As String
    Dim i As Integer
    Dim current As String
    current = ActiveSheet.Name
    Sheets(1).Activate
    Do
        theFlag = 0
        For i = 1 To (Sheets.Count - 1)
            sheet1 = UCase(Sheets(i).Name)
            Sheet2 = UCase(Sheets(i + 1).Name)
            If sheet1 > Sheet2 Then
                Sheets(Sheet2).Move Before:=Sheets(sheet1)
                theFlag = 1
            End If
        Next I
    Loop Until theFlag = 0
    Sheets(current).Activate
    End Sub
     
    Sub SortSheetsDescending()
    ' Macro recorded 1/9/03 by Daxton Allen
    Dim theFlag As Integer
    Dim sheet1 As String
    Dim Sheet2 As String
    Dim i As Integer
    Dim current As String
    current = ActiveSheet.Name
    Sheets(1).Activate
    Do
        theFlag = 0
        For i = 1 To (Sheets.Count - 1)
            sheet1 = UCase(Sheets(i).Name)
            Sheet2 = UCase(Sheets(i + 1).Name)
            If sheet1 < Sheet2 Then
                Sheets(Sheet2).Move Before:=Sheets(sheet1)
                theFlag = 1
            End If
        Next i
    Loop Until theFlag = 0
    Sheets(current).Activate
    End Sub
    Last edited by Aussiebear; 04-29-2023 at 07:57 PM. Reason: Adjusted the code tags

Posting Permissions

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