Skip to main content

How to sort multiple rows or columns independently at once in Excel?

In Excel, you can apply the Sort feature to sort only one row or column in a range of columns, but, if you need to sort multiple rows or columns independently at once to get the following screenshot shown. Are there any quick ways to solve this task in Excel?

doc sort multiple columns 1

Sort multiple columns independently at once with VBA code

Sort multiple rows independently at once with VBA code


arrow blue right bubble Sort multiple columns independently at once with VBA code

To sort multiple columns independently in an ascending order, the following VBA code may help you, please do as this:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Sort multiple columns independently at once:

Sub SortIndividualJR()
'Updateby Extendoffice
    Dim xRg As Range
    Dim yRg As Range
    Dim ws As Worksheet
    Set ws = ActiveSheet
    On Error Resume Next
    Set xRg = Application.InputBox(Prompt:="Range Selection:", _
                                    Title:="Kutools for excel", Type:=8)
    Application.ScreenUpdating = False
    For Each yRg In xRg
        With ws.Sort
            .SortFields.Clear
            .SortFields.Add Key:=yRg, Order:=xlAscending
            .SetRange ws.Range(yRg, yRg.End(xlDown))
            .Header = xlNo
            .MatchCase = False
            .Apply
        End With
    Next yRg
    Application.ScreenUpdating = True
End Sub

3. Then press F5 key to run this code, and a prompt box is popped out to remind you select the data range that you want to sort based on each column, see screenshot:

doc sort multiple columns 2

4. And then click OK, each columns have been sorted dependently at once, see screenshot:

doc sort multiple columns 1


arrow blue right bubble Sort multiple rows independently at once with VBA code

If you want to sort multiple rows independently, here also is a VBA code for you.

1. Select the data that you want to sort based on each rows.

doc sort multiple columns 3

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Sort multiple rows independently at once:

Sub SortIndividualR()
'Updateby Extendoffice
    Dim xRg As Range, yRg As Range
    If TypeName(Selection) <> "Range" Then Exit Sub
    Set xRg = Selection
    If xRg.Count = 1 Then
        MsgBox "Select multiple cells!", vbExclamation, "Kutools for Excel"
        Exit Sub
    End If
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    Application.ScreenUpdating = False
    For Each yRg In xRg.Rows
        yRg.Sort Key1:=yRg.Cells(1, 1), _
        Order1:=xlAscending, _
        Header:=xlNo, _
        Orientation:=xlSortRows
    Next yRg
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With
    Application.ScreenUpdating = True
End Sub

4. Then press F5 key to run this code, the data in each rows have been sorted at once, see screenshot:

doc sort multiple columns 4

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
My data ranges from 0-100; When I Try to sort multiples rows at once, it starts the data off with the 100s, then sorts the rest numerically least to greatest, putting the 100s at the least side of the range. How can I fix this?
This comment was minimized by the moderator on the site
Update; I've realized it is sorting by the first digit in the number only - How do I get it to sort by the whole number?
This comment was minimized by the moderator on the site
Hi, Devyn,
The code works well in my worksheet. Could you upload your Excel file or data screenshot here? So that, we can help to check where the problem is?
Thank you!
This comment was minimized by the moderator on the site
Спасибо тебе человек!!
This comment was minimized by the moderator on the site
excellent post, thank you very much!
This comment was minimized by the moderator on the site
You have just saved me several headaches with this solution! Thanks a ton!
This comment was minimized by the moderator on the site
Thank you so much for this. It really helped. I would also like to know how to sort by color. I have 26 columns, each having different types of items identified by the font color. I would like to alphabetize all the columns individually but in a specific color order. How do I do this?
This comment was minimized by the moderator on the site
I love this, I'm curious as to the functionality of sorting by color for each column individually. I tried this but it didn't work:


Dim xRg As Range
Dim yRg As Range
Dim ws As Worksheet
Set ws = ActiveSheet
On Error Resume Next
Set xRg = Application.InputBox(Prompt:="Range Selection:", _
Title:="Kutools for excel", Type:=8)
Application.ScreenUpdating = False
For Each yRg In xRg
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=yRg, _
SortOn:=xlSortOnCellColor, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange ws.Range(yRg, yRg.End(xlDown))
.Header = xlNo
.MatchCase = False
.Apply
End With
Next yRg
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
¿Cómo puedo ordenar por color múltiples filas de forma independiente y que las celdas que no tengan color estén a la derecha?
This comment was minimized by the moderator on the site
When I try to sort the columns it sorts data outside of the sected range! Why is this?
This comment was minimized by the moderator on the site
It works great ! thank you !
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations