Yes, you can reorder rows in Excel using the Sort feature, or by dragging and dropping them directly. You can also use a helper column with a ranking formula to sort by multiple criteria or generate a custom order. This guide covers the standard method, the drag-and-drop approach, and more advanced techniques for handling complex data.
What You'll Need
- An active Microsoft Excel workbook (Windows, Mac, or Web). The steps below cover the desktop application, which is the most complete, but the web and mobile versions follow similar logic.
- A dataset containing headers (column titles) in the first row. Excel uses these headers to decide which column to sort by.
- A stable internet connection if you are using the Excel for the Web version.
Step-by-Step: Sorting Single Columns
This is the most common way to reorder data, whether you want to see a list alphabetically, numerically, or chronologically.
- Select the data: Click on any single cell within the column you want to sort. For example, if you want to reorder a list of employees by their last name, click on the header cell (e.g., "Last Name") or any cell within the "Last Name" column.
- Open the Sort menu: Navigate to the "Data" tab on the Excel ribbon at the top of the window. On the far left of this tab, you will see a button labeled "Sort." Click it.
- Choose the sort key: In the "Sort" dialog box that appears, you will see a dropdown menu next to "Sort by." Select the column header you want to use for the ordering. This is the primary column Excel will use to decide where each row goes.
- Select the sort order: Look for the "Sort On" dropdown menu. By default, it is set to "Values," which is correct for text and numbers. Select "Cell Color," "Font Color," or "Cell Icon" if you have conditional formatting applied and want to sort based on those visual cues. If you only want to sort by values, leave this as is.
- Choose the order: In the "Order" dropdown menu, select how you want the data arranged. For text, choose "A to Z" for ascending alphabetical order or "Z to A" for descending. For numbers, choose "Smallest to Largest" or "Largest to Smallest." For dates, choose "Oldest to Newest" or "Newest to Oldest.
- Apply the sort: Click the "OK" button. Excel will instantly reorder all the rows in your dataset based on the criteria you selected. The data in other columns will move with their corresponding rows, preserving the original relationships in your data.
Step-by-Step: Sorting Multiple Columns Simultaneously
Sometimes, a single column isn't enough. For instance, you might have a list of products where you want to sort by Category first, and then by Product Name within each Category. You can do this in one go.
- Select your data: Click on any cell within your entire dataset, not just one column. It is best practice to select the entire block of data you want to sort, from the top-left corner to the bottom-right corner.
- Open the Sort menu: Go to the "Data" tab and click the "Sort" button.
- Add a second sort level: In the dialog box, you will see a section labeled "Then by." Click the "Add Level" button below this section. This will create a new, empty row for a second sort condition.
- Configure the second level: In the new "Then by" row, use the dropdown menus to choose your secondary sort key, sort type, and order. For the example above, you would select "Category" as the first key and "Product Name" as the second key.
- Continue adding levels: You can add as many levels as you need by clicking "Add Level" repeatedly. Excel will sort by the first key, and then, within each group of identical values for the first key, it will sort by the second key, and so on.
- Apply the sort: Click "OK" to finalize the multi-column sort. Excel will now organize your entire list according to the hierarchy you defined.
Step-by-Step: Drag-and-Drop Method
This method is perfect for making small, manual adjustments to your data. It is intuitive but less precise than sorting for large datasets.
- Enable drag-and-drop: By default, this feature is turned on. If you find you cannot drag rows, go to the "File" tab, select "Options,” and then the "Advanced" category. On the right side, under "Editing options,” ensure the box labeled "Allow cell drag and drop" is checked.
- Select the rows: Click and hold down your mouse button on the row number on the left side of the Excel window. This is the gray area where the row numbers like 1, 2, 3 are located. Drag your mouse to select the specific rows you want to move. You can hold the Shift key while clicking to select multiple non-contiguous rows.
- Click and hold the border: After you have selected the rows, click and hold your mouse button on the border of the selected area. The cursor will change to a four-headed arrow.
- Drag the rows: While holding the mouse button, move your cursor to the new location where you want to place the rows. A gray outline will show you where the rows will drop.
- Release the mouse: Click to drop the rows into their new position. You can also hold the Alt key while dragging to snap the rows to the grid lines, which can be helpful for precise alignment.
Step-by-Step: Using a Helper Column for Custom Order
Standard sorting puts items in A to Z or numerical order. But what if you have a specific, non-alphabetical list, like "Priority 1, Priority 2, Priority 3"? You can create a "helper column" to assign a number to each priority level.
- Insert a new column: Click on the column header immediately to the right of your data. Press the "Insert" button on the "Home" tab, or right-click and choose "Insert" to add a new column.
- Name the helper column: In the new column, enter a descriptive header, such as "Priority Order" or "Sort Rank.
- Enter your ranking values: In the cells below the header, enter the numbers that represent your custom order. For example, type "1" next to "High Priority," "2" next to "Medium Priority," and "3" next to "Low Priority.
- Apply a standard sort: Now, sort your main data by this new helper column. Excel will reorder your rows based on the numbers you entered, effectively creating a custom order.
- Hide the helper column: Once the sorting is complete, you can hide the helper column to keep your data clean. Right-click on the column header and choose "Hide.
Common Mistakes
Reordering data in Excel is powerful, but it is easy to make mistakes if you aren't careful. Here are the most common errors to avoid.
One of the most frequent mistakes is not selecting the entire dataset before starting a sort. If you only select a single column, Excel will attempt to sort only that column, leaving the rest of your data scrambled and out of sync with the column you just sorted. To fix this, always ensure your selection includes all the columns you want to move with the rows.
Another common error is trying to use the drag-and-drop method for large, complex datasets. This method is best for small, manual adjustments. For thousands of rows, it is slow and prone to errors. Instead, use the Sort feature in the Data tab for large-scale reordering.
Finally, be careful when sorting by a column that contains both text and numbers. Excel will often misinterpret these mixed values, placing numbers before text or in an unexpected order. To avoid this, clean your data first by converting numbers stored as text into actual numbers using the "Convert to Number" option in the "Error Checking" dropdown arrow on the left side of the formula bar.
Tips
To get the most out of Excel's reordering features, keep these tips in mind.
Always keep your data in a single, contiguous table. If your data is split across multiple sheets or has blank rows in between, the Sort feature will not work correctly. Consolidate your data into one sheet and remove any blank rows before attempting to sort.
Use the "Custom Sort” option to gain more control over your sorting. While the basic sort menu is useful, the Custom Sort dialog box allows you to sort by cell color, font color, and cell icons. This is incredibly helpful when you want to group data visually rather than by its values.
For the most flexible and powerful sorting, consider using a helper column with a ranking formula. Instead of manually typing numbers like 1, 2, 3, you can use the RANK.EQ function to automatically assign rankings based on a specific value. This makes it easy to change the sorting order later by simply changing the values in the helper column.
Troubleshooting
If your data isn't reordering the way you want it to, here are some steps to fix the problem.
If the Sort button is grayed out and unclickable, it usually means you haven't selected the entire dataset. Click on the top-left cell of your data and press Ctrl+A to select all the data in the sheet, or drag your cursor to encompass the entire block of data you want to sort.
If Excel is not recognizing your text or numbers correctly during a sort, the data might be formatted as text. To fix this, select the column with the data, go to the "Data" tab, and look for the "Text to Columns” button. Click it and choose "Finish” without changing any settings. This will re-import the data and often fix formatting issues.
If you are trying to sort by a date but the dates appear in a strange order, like February before January, the dates might be stored as text rather than real dates. Click on the column, press Ctrl+1 to open the Format Cells dialog, and ensure the "Date” category is selected with a standard date format like "3/14/2001.” If this doesn't work, the dates may need to be converted using the TEXT function.
Frequently Asked Questions
Can I undo a sort?
Yes. Excel keeps a history of your last 100 actions. You can simply press Ctrl+Z immediately after a sort to revert the changes. Alternatively, you can use the “Undo” arrow in the Quick Access toolbar.
How do I sort data without moving the header row?
When you select a cell within your data and click the Sort button, Excel will automatically detect that the first row is a header and will keep it in place while sorting the rows below it. You do not need to do anything special.
What does the "Sort On” option do?
The "Sort On” option allows you to sort based on properties of the cell rather than its value. You can sort by cell color, font color, or cell icon. This is useful for grouping data that has been highlighted with conditional formatting.
Can I sort by multiple criteria at once?
Yes. In the Sort dialog box, you can click the "Add Level” button to add a second, third, or even fourth sort criteria. Excel will sort by the first criterion, and then within each group of identical values, it will sort by the second criterion, and so on.
Why is my data not sorting correctly?
If your data is not sorting correctly, it is likely due to formatting issues. Ensure that your data is in a single, contiguous table, that there are no blank rows, and that your data types are correct (e.g., dates are actually dates, and numbers are not stored as text).
Is there a way to sort by a list I created myself?
Yes. You can create a custom list in Excel. Go to the "File” tab, select "Options,” and then the "Advanced” category. Scroll down to the "General” section and click the "Custom Lists...” button. Here you can define your own order, and then you can use the "Custom Sort” feature to sort by that list.