Forum Discussion

Gretc1865's avatar
Gretc1865
Copper Contributor
Feb 20, 2022

A to Z format

I can't figure out how to sort my spreadsheet alphabetically...not just by column or row, but the whole spreadsheet. I want to have it listed alphabetically and it would also help me eliminate duplicates. It's a list of book titles and I'm hoping that I can alphabetize from left to right - there are three cells across and I'm trying to get them A to Z starting with the first cell, than the next cell in the row, then another cell and then continuing on this way with the first cell of the second row, then two more cells and then wrapping along to the third row, and then fourth, and so on. I have no idea if this even makes sense and I'm obviously Excel uneducated. Hopefully it's simple and I just need to learn it...any suggestions?

3 Replies

  • HiGretc1865 

     

    This post to help you to sort your sheets 

    I believe you will need to use VBA, open the VBA editor by pressing Alt+F11 --> from Insert menu -> click on  Module.

    Copy the below code and save the file.

    Now, to sort the sheets, open the Macro window by pressing Alt+F8, then run the macro with the name Sort_Active_Book

     

    Sub Sort_Active_Book()
    Dim i As Integer
    Dim j As Integer
    Dim iAnswer As VbMsgBoxResult
    '
    ' Prompt the user as which direction they wish to
    ' sort the worksheets.
    '
       iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
         & "Clicking No will sort in Descending Order", _
         vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
       For i = 1 To Sheets.Count
          For j = 1 To Sheets.Count - 1
    '
    ' If the answer is Yes, then sort in ascending order.
    '
             If iAnswer = vbYes Then
                If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
                   Sheets(j).Move After:=Sheets(j + 1)
                End If
    '
    ' If the answer is No, then sort in descending order.
    '
             ElseIf iAnswer = vbNo Then
                If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then
                   Sheets(j).Move After:=Sheets(j + 1)
                End If
             End If
          Next j
       Next i
    End Sub

     

     

  • harshulz's avatar
    harshulz
    Iron Contributor

    Gretc1865 
    go to data tab
    under sort & filter choose sort command as shown below 
    get to sort by drop down and select first priority that you want to arrange

    lets say column b is your priority and order it a to z
    then click on add level and choose remaining priorities

    final result shown below

     

     

Resources