How to Sort Data by Row Not Column in Excel (2 Easy Methods)

Get FREE Advanced Excel Exercises with Solutions!

In this article, we will learn to sort data by row not column in Excel. By default, Excel sorts data by column. But in some cases, we need to sort data by row in our dataset. Today, we will discuss 2 methods to sort data by row not column in Excel.


How to Sort Data by Row Not Column in Excel (2 Easy Methods)

To explain these methods, we will use a dataset that contains information about the Sales Amount for the first four months of some sellers.


1. Use Excel Custom Sort to Sort Data by Row Not Column

We can use the custom sort in Excel to sort data by row. In Excel, we can sort data by a single row and also by multiple rows. In the following sub-methods, we will discuss both of them.

1.1 Sort Single Row

In this sub-method, we will try to sort data by a single row. Here, our dataset will contain two rows with values and a header.

Let’s follow the steps below to learn more.

STEPS:

  • First of all, select the range in your dataset. We have selected Cell B5 to F7.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Secondly, go to the Home tab and select Sort & Filter. A drop-down menu will occur.
  • Select Custom Sort from the drop-down menu. It will open the Sort window.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Thirdly, check ‘My data has headers’ if your dataset has headers.
  • Then, select Options.

Use Excel Custom Sort to Sort Data by Row Not Column

  • After selecting options, a dialog box will pop up. Select Sort left to right and click OK.

Use Excel Custom Sort to Sort Data by Row Not Column

  • After that, select the row number from the Row field and the order you want to sort the data from the Order field.
  • We want to sort the dataset by Row 6 in descending order. So, we have selected Row 6 in the Row field and Largest to smallest in the Order field.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Finally, click OK to see results like the image below. Here, you can see that Row 6 is sorted in descending order. The dataset is sorted by row.

Use Excel Custom Sort to Sort Data by Row Not Column

Read More: How to Sort Alphabetically in Excel and Keep Rows Together


1.2 Sort Multiple Rows

You can also sort data by multiple rows. This procedure is almost the same as the previous sub-method. Here, our dataset will contain multiple rows with values. So, without further ado, let’s observe the steps below.

STEPS:

  • In the first place, select the range where you want to apply the Custom Sort.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Secondly, go to the Home tab and select Sort & Filter.
  • Then, select Custom Sort from the drop-down menu.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Now, check ‘My table has headers’ if your selected dataset contains headers.
  • After that, select Options. A message box will appear.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Select Sort left to right from the message box and click OK to proceed.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Select the row by which you want to sort the data first and then, select the order.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Next, select Add Level to add another row.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Here, select the row by which you want to sort the data second, and then, select the order.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Do the same if you want to add more rows.

Use Excel Custom Sort to Sort Data by Row Not Column

  • Finally, click OK to see results like the picture below. Here, the dataset is sorted by Row 6, and then by Row 7, Row 8, and Row 9 respectively.

Use Excel Custom Sort to Sort Data by Row Not Column

Read More: How to Sort Multiple Columns in Excel


2. Sort Data by Row Not Column with Excel VBA

VBA is always useful to perform different tasks in Excel very easily. Today, we will show some short macros to sort data by row in our Excel worksheet. Here, we will use a dataset that describes the sales amount of some sellers.

Let’s pay attention to the steps below to learn more.

STEPS:

  • To begin with, go to the Developer tab and select Visual Basic. It will open the Visual Basic window. You can also open it by pressing Alt + F11.

  • In the Visual Basic window, select Insert and then, Module. This will open the Module window. Or, double-click on the sheet where you want to apply the code to open the Module window.
  • Now, type the code in the Module window to sort by row in ascending order:
Sub Sort_by_Row()
Range("C5:F8").Sort Key1:=Range("C5"), _
                     Order1:=xlAscending, _
                     Orientation:=xlSortRows
End Sub

Sort Data by Row Not Column with Excel VBA

  • After that, press Ctrl + S to save the code and then, close the Visual Basic window.
  • Next, select Macros from the Developer tab to open the Macro window.

  • Then, select and Run the code from the Macro window.

  • After running the code, you will see results like the screenshot below.

  • To sort by row in descending order, type the code below in the Module window:
Sub Sort_by_Row()
Range("C5:F8").Sort Key1:=Range("C5"), _
                     Order1:=xlDescending, _
                     Orientation:=xlSortRows
End Sub

  • In the end, run the code by pressing the F5 key to see results in descending order.

Read More: Sorting Columns in Excel While Keeping Rows Together


Things to Remember

In both methods, we have sorted the dataset by the first row of our selected range. It is not possible to sort each row individually in ascending or descending order.


Download Practice Book

Download the practice book here.


Conclusion

We have demonstrated 2 easy methods to Sort Data by Row not Column in Excel. We have also discussed the method with VBA. I hope these methods will help you to perform your tasks easily. Furthermore, we have also added the practice book at the beginning of the article. You can download it to learn more. Last of all, if you have any suggestions or queries, feel free to ask in the comment section below.


Related Articles


<< Go Back to Sort in Excel | Learn Excel

What is ExcelDemy?

ExcelDemy - Learn Excel & Get Excel Solutions Center provides online Excel training , Excel consultancy services , free Excel tutorials, free support , and free Excel Templates for Excel professionals and businesses. Feel free to contact us with your Excel problems.
Mursalin Ibne Salehin
Mursalin Ibne Salehin

Mursalin Ibne Salehin holds a BSc in Electrical and Electronics Engineering from Bangladesh University of Engineering and Technology. Over the past 2 years, he has actively contributed to the ExcelDemy project, where he authored over 150 articles. He has also led a team with content development works. Currently, he is working as a Reviewer in the ExcelDemy Project. He likes using and learning about Microsoft Office, especially Excel. He is interested in data analysis with Excel, machine learning,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo