How to Sort Multiple Rows in Excel (2 Ways)

Sorting rows is one important task in any form of data analysis. Excel provides different methods to sort rows in different scenarios with different results. In this tutorial, I am going to show you how to sort multiple rows in Excel.

You can download the workbook with all the examples used to demonstrate this guide below.

2 Ways to Sort Multiple Rows in Excel

I will be covering two major different rows sorting in Excel here, Vertical and Horizontal. The first one focuses on vertical sorting and the second one is horizontal row sorting. Each has its own sub-methods to perform the operations.

1. Sort Multiple Rows Vertically in Excel

There are three major ways you can sort out a big chunk of unorganized data in Excel. I am going to show each of them in their individual sections. But, for each one, I will be using the following dataset.

It is a list of best-selling books of all time. I will be sorting this dataset out into different categories in each section.

1.1 Using Custom Sort Command

The Sort & Filter tool is one of the most used tools in all of Excel and can be used to easily sort multiple rows or columns in Excel. In this tool, there is a Custom Sort command that I will be using in the dataset to sort out which books came out first by sorting them by their published year.

Steps:

• First, select the dataset you want to sort.

• In the ribbon, go to the Home tab. Under the Editing group, select Sort & Filter. Then select Custom Sort from the drop-down menu.

• Now in the Sort box that popped up, in the Sort by field select Published, and in the Order field, select Smallest to Largest.

• Then click on OK. You will have your rows sorted.

1.2 Applying SORT Function

There is a built-in function called the SORT function to sort multiple rows or columns in Excel. The function takes one primary and multiple optional arguments. It takes an array as the primary argument that it is going to sort. The secondary arguments include sort index, sort order(1 for ascending and -1 for descending order), and a boolean depending on if you are sorting column or row.

I am going to use the same dataset to achieve the same result. But, this time, with the SORT function.

Steps:

• First, select a range of cells equal to the dataset you are going to sort.
• Then write down the following formula.

`=SORT(B5:E14,3,1)`

• Now press Ctrl+Shift+Enter on your keyboard. You will have your dataset sorted by published year.

1.3 Embedding VBA Code

You can use Microsoft Visual Basic for Applications (VBA) to sort out multiple rows in Excel. To do this, you first need the Developer tab shown on your ribbon. If you donâ€™t have that, enable the Developer tab.

Once you have the tab, follow these steps to get sorted rows. I will be using the same dataset as the above methods for this one.

Steps:

• First, in the Developer tab, under the Code group, select Visual Basic.

• After that, a VBA window will pop up. In it, go to Insert>Module.

• Now, in the module, copy the following code.
``````Sub Sort_Individual_Rows()
Â Â Â  Dim xRnge As Range
Â Â Â  Dim yRnge As Range
Â Â Â  Dim wsht As Worksheet
Â Â Â  Set wsht = ActiveSheet
Â Â Â  On Error Resume Next
Â Â Â  Set xRnge = Application.InputBox(Prompt:="Range Selection:", _
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  Title:="Powered by Exceldemy.com", Type:=8)
Â Â Â  Application.ScreenUpdating = False
Â Â Â  For Each yRnge In xRnge
Â Â Â Â Â Â Â  With wsht.Sort
Â Â Â Â Â Â Â Â Â Â Â  .SortFields.Clear
Â Â Â Â Â Â Â Â Â Â Â  .SortFields.Add Key:=yRnge, Order:=xlAscending
Â Â Â Â Â Â Â Â Â Â Â  .SetRange wsht.Range(yRnge, yRnge.End(xlDown))
Â Â Â Â Â Â Â Â Â Â Â  .Header = xlNo
Â Â Â Â Â Â Â Â Â Â Â  .MatchCase = False
Â Â Â Â Â Â Â Â Â Â Â  .Apply
Â Â Â Â Â Â Â  End With
Â Â Â  Next yRnge
Â Â Â  Application.ScreenUpdating = True
End Sub``````
• Once you are done, press F5 on your keyboard to run the code.
• Now a range selection box will pop up. Select the range of cells B5:E14.
• Then click on OKÂ and you will have your row values sorted.

Note: This code will sort out all the row values of all columns.

Read More: VBA to Sort Column in Excel (4 Methods)

2. Sort Multiple Rows Horizontally in Excel

You can sort multiple rows horizontally in Excel. Letâ€™s say you have a dataset horizontally aligned like this.

You may want to sort the rows in ascending or descending manner now. You can achieve the sorted result for these rows by the three methods again.

2.1 Applying Custom Sort Command

First, I will be using the Excel Custom Sort command to sort these rows horizontally. For a detailed guide follow these steps.

Steps:

• First, select the range of cells you want to sort.

• Then go to the Home tab and then select Editing> Sort & Filter > Custom Sort.

• Now, in the Sort box, select Row 5 or Row 6 depending on which row you want to sort in the Sort by field, and select Smallest to Largest in the OrderÂ field.

• Finally, click on OK. You will have your rows sorted horizontally.

Read More: How to Create Custom Sort List in Excel

2.2 Utilizing SORT Function

You can also use the SORT function to sort multiple rows in Excel horizontally. The function can take several arguments. It takes an array as the primary argument. The secondary arguments include sort index, sort order(1 for ascending and -1 for descending order), and a boolean depending on if you are sorting column or row.

For a more detailed guide, follow these steps.

Steps:

• First, select a range of cells equal to the length of your dataset.

• Write down the following formula in the cell.

`=SORT(C5:H6,1,1,TRUE)`

• Now press Ctrl+Shift+Enter on your keyboard. You will have your rows sorted horizontally.

2.3 Embedding VBA Code

To achieve the result by using Microsoft Visual Basic for Applications (VBA) you need the Developer tab showing on your ribbon. If you donâ€™t have that, enable the Developer tab.

Once you have the tab, follow these steps to sort multiple rows in Excel horizontally.

Steps:

• First, select the range of cells.

• After that, in your ribbon, go to the Developer tab. And in the Code group, select Visual Basic.

• Now in the VBA window that popped up, go to Insert and select Module.

• Then in the Module, copy the following code.
``````Sub Sort_Rows()
Â Â Â  Dim xRnge As Range
Â Â Â  Dim yRnge As Range
Â Â Â  If TypeName(Selection) <> "Range" Then Exit Sub
Â Â Â  Set xRnge = Selection

Â Â Â  If xRnge.Count = 1 Then
Â Â Â Â Â Â Â  Exit Sub
Â Â Â  End If

Â Â Â  With Application
Â Â Â Â Â Â Â  .ScreenUpdating = False
Â Â Â Â Â Â Â  .EnableEvents = False
Â Â Â Â Â Â Â  .Calculation = xlCalculationManual
Â Â Â  End With

Â Â Â  Application.ScreenUpdating = False
Â Â Â  For Each yRnge In xRnge.Rows
Â Â Â Â Â Â Â  yRnge.Sort Key1:=yRnge.Cells(1, 1), _
Â Â Â Â Â Â Â  Order1:=xlAscending, _
Â Â Â Â Â Â Â  Header:=xlNo, _
Â Â Â Â Â Â Â  Orientation:=xlSortRows
Â Â Â  Next yRnge

Â Â Â  With Application
Â Â Â Â Â Â Â  .ScreenUpdating = True
Â Â Â Â Â Â Â  .EnableEvents = True
Â Â Â Â Â Â Â  .Calculation = xlCalculationAutomatic
Â Â Â  End With

Â Â Â  Application.ScreenUpdating = True
End Sub``````
• Finally, press F5 to run the code. It will sort your rows horizontally.

Conclusion

These were the different methods you can use to sort multiple rows in Excel both vertically and horizontally. Hope you have found this article helpful and informative. If you have any questions or suggestions let us know down below. For more guides like this visit Exceldemy.com.

Related Articles

Abrar-ur-Rahman Niloy

Hi! my name is Abrar-ur-Rahman Niloy. I have completed B.Sc. in Naval Architecture and Marine Engineering. I have found my calling, if you like, in Data Science and Machine Learning and in pursuing so, I have realized the importance of Data Analysis. And Excel is one excel-lent tool do so. I am always trying to learn everyday, and trying to share here what I am learning.

We will be happy to hear your thoughts

5 Excel Hacks You Never Knew