A simple but very powerful tool
Two of Excel’s primary functions are to allow you to manipulate and view data from different perspectives, and one of the program’s more simple but powerful tools for doing so is the Sort function.
Whether it’s simple ascending/descending sorts, sorting on more than one variable to display data in groups or to maintain row integrity, or simple alphanumeric sorts to keep your tabular data orderly, sorting data in Excel is an essential skill.
Few programs are better suited for sorting tabular data than Excel, and your sorts can run from the simple and relatively uncomplicated to the highly sophisticated. While Excel’s sorting prowess—what you can do with the right data set and a little knowledge of the inner workings of the program—is indeed robust and in-depth, today’s tech tip focuses on two basic types of sorts, as follows:
- Sorting data on a single column
- Sorting data on multiple columns
Spreadsheets are, of course, made up of columns and rows of cells, or tabular data, where each column comprises a logical division of facts, figures, or any other details by category, such as, say, names, addresses, currency, parts numbers, and so on—depending on the type of spreadsheet. Rows, on the other hand, display people, objects, or figures side-by-side or in the same instance or occurrence.
Depending on the type of spreadsheet and the data it contains, such as a tabular list of names, addresses, phone numbers, and other pertinent data, rows are frequently similar to database records.
When you sort rows of data, each row must maintain its integrity, without inadvertently moving data from one row to another, which, as you’ll see further down, is where sorting data on multiple columns comes in handy.
Sorting on a Single Field
You can sort the records in your spreadsheet by rows, and you can sort the cells within records by columns. You can, of course, specify ascending or descending sort orders. By default, ascending / alphanumerically, the program arranges text from A to Z and numbers from smallest to largest. Sorting with a descending sort order, of course, reverses the older from Z to A, or so that larger numbers start at the top.
As with many functions in Excel, there are a few ways to perform a simple sort; everything you need for this type of sort, though, resides on the right mouse button flyout-menu, as shown below.
- Right-click a field in the column upon which you want to sort the spreadsheet to open the popup menu.
- Scroll down and hover the cursor over Sort to open the flyout menu.
- Click Sort A to Z for ascending or Sort Z to A descending (Note that Excel does not include the data in cells in row 1 in the sort; the program assumes that this row holds your column labels, or headers.).
This simple sort works for many types of data, except when your rows and columns have identical, or duplicate, data. In these instances, you must sort on two or more columns, coming up next.
Sorting Records on Multiple Fields
Depending on the complexity of your data, you may need to sort on more than one column. Perhaps the best example is sorting a database alphabetically in last-name order. Say that your data has several people with the same last names. In these instances, you’ll want to make sure that Linda Johnson comes before Lydia Johnson, and Cherri Anderson displays after Charles Anderson…You get the idea.
You can set up custom searches with multiple criteria from the Sort dialog box, like this.
- Click a cell in the first column of data you want to sort.
- Click Data just beneath the title bar to open the Data ribbon. (The ribbon is, of course, the row of contextual tabs across the top of the application window.)
- In the Sort & Filter section, click the Sort button to open the Sort dialog box.
- Click the Sort by drop-down and choose the first column name to sort on. (Note that Excel displays the content in row 1 of the column, which in this case holds the column labels. You can turn this option off by unchecking the My data has headers checkbox.)
- Click Add Level to add another column to the sort order.
- Click the Then by drop-down and choose the next column to sort on.
- Repeat Steps 6 and 7 as needed to configure the parameters of your sort.
Clicking around in the Sort dialog box reveals several different options for modifying your sorts, though some of them, unless you know exactly how each one affects your sort, will most likely produce unwanted results.
- Click OK.
- If you get a Sort Warning dialog box, select Expand the selection and then click Sort.
Besides, when you choose a column, Excel analyzes the contents of the cells in that column and makes educated guesses as to what values should populate the Sort on and Order fields. Unless you have a specific (and logical) reason for changing these, don’t. (Unless you’re experimenting, of course. I always encourage that—and Excel’s Undo feature works marvelously.)
As I’m sure you can imagine, this is just the beginning of how you can sort data in Excel. It’s important to remember, though, that unless you’re careful, using the wrong parameters can juxtapose your data and completely change its position in the spreadsheet. Sort is fast and easy to setup. The good news is that Undo is fast, too. Don’t be afraid to Undo and try again. And again.