How to Sort Multiple Columns in Excel Independently of Each Other (2 Easy Ways)

We have a dataset of fruits with their delivery information and quantities. We are going to sort those columns independently.

how to sort multiple columns in excel independently of each other


Method 1 – Using VBA Code

Steps:

  • Go to the Developer tab.
  • Select the Visual Basic command.
  • The visual basic window will appear.

openong visual basic window to show how to sort multiple columns in excel independently of each other

  • Select Insert.
  • Choose Module.
  • A module will appear.

inserting module to show how to sort multiple columns in excel independently of each other

  • In the module, insert the following code and save it.
Sub Sort_multiple_columns()
    Dim xRg As Range 'Declare range for Columns
    Dim yRg As Range 'Declare range for Rows
    Dim Am_ws As Worksheet 'Name the WorkSheet
    Set Am_ws = ActiveSheet
    On Error Resume Next
    Set xRg = Application.InputBox(Prompt:="Range Selection:", _
                                    Title:="Sort Multiple Columns", Type:=8)
    Application.ScreenUpdating = False
    For Each yRg In xRg
        With Am_ws.Sort
            .SortFields.Clear
            .SortFields.Add Key:=yRg, Order:=xlAscending
            .SetRange Am_ws.Range(yRg, yRg.End(xlDown))
            .Header = xlNo
            .MatchCase = False
            .Apply
        End With
    Next yRg
    Application.ScreenUpdating = True
End Sub

writing and saving code to show how to sort multiple columns in excel independently of each other

  • Go to the Developer tab.
  • Choose Macros. You’ll get a Macros window

  • Select the code name.
  • Click on Run.
  • You’ll get an input box.

running code to show how to sort multiple columns in excel independently of each other

  • Select the B5:F15 range as the desired range.
  • Click OK.

  • All the columns will be sorted independently.


Method 2 – Sort Multiple Columns in Excel Independently of Each Other by String Length

Steps:

  • Select the B13 cell and insert:
=SORTBY(B5:B10, LEN(B5:B10),1)
  • Hit the Enter button.
  • The B5:B10 range will be sorted by the text length.

sorting fruit name by text length to show how to sort multiple columns in excel independently of each other

  • Choose the C13 cell and enter:
=SORTBY(C5:C10, LEN(C5:C10),1) 
  • Press Enter.
  • The C5:C10 range will be sorted according to lower to greater numbers.

  • Choose the D13 cell and enter the following formula:
=SORTBY(D5:D10, LEN(D5:D10),1)
  • Press the Enter button.
  • Consequently, we will have a sorted D5:D10 range according to earlier to later date.

  • Select the E13 cell and insert the following formula:
=SORTBY(E5:E10, LEN(E5:E10), 1)
  • Press Enter.
  • The E5:E10 range will be sorted.

  • Click on the F13 cell and type the formula below:
=SORTBY(F5:F10, LEN(F5:F10), 1)

  • Hit Enter.
  • The column will be sorted by lowest to highest prices.

Formula Explanation

  • LEN(F5:F16) will find the length of the selected rows.
  • SORTBY function sorts them according to their length number.

Download the Practice Workbook


Further Readings


<< Go Back to Sort Columns in Excel | Sort in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Md. Abdullah Al Murad
Md. Abdullah Al Murad

Md. Abdullah Al Murad is a computer engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in C, C++, Python, JavaScript, HTML, SQL, MySQL, PostgreSQL, Microsoft Office, and VBA and goes beyond the basics. He holds a B.Sc. in Computer Science and Engineering from American International University-Bangladesh. He has transitioned into the role of a content developer. Beyond his work, find... Read Full Bio

2 Comments
  1. The first method is wrong. sort by, then by,… does not sort independently

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo