Yes, you can sort numbers in Excel without manually rearranging them using the SORTBY function. This formula uses the values you want to order as the sort key, allowing you to rearrange a dataset based on a specific column or set of columns in a single step. It works in Excel 365 and Excel 2021.

What You'll Need

  • A computer with Microsoft Excel installed (Excel 365 or Excel 2021).
  • A dataset containing the numbers you wish to reorder.
  • A target range or a new worksheet where the sorted data will appear.

If you have a much older version of Excel and do not have the SORTBY function, you will need to use the older Sort feature in the Data tab or the INDEX and MATCH functions to achieve a similar result.

Step-by-Step

Follow these steps to use the SORTBY formula to order your numbers. This example assumes you have a list of items in the range A2:A10 and their corresponding numerical values in the range B2:B10. You want to list the items in order from the smallest number to the largest.

  1. Open your Excel workbook and navigate to the worksheet containing your data.
  2. Select an empty cell where you want the sorted list to begin. This is typically the first cell in the column where you want the results to appear.
  3. Start typing the SORTBY formula by entering the equals sign (=) followed by the function name: SORTBY.
  4. Identify the array to be sorted. This is the range of data you want to rearrange. In our example, this is the list of items in column A. Do not include the headers (like the word "Item"). Type the range reference: A2:A10.
  5. Identify the sort by array. This is the range of numbers that determines the order. In our example, this is the values in column B. Type the range reference: B2:B10.
  6. Close the function. Press the closing parenthesis key () on your keyboard to complete the formula syntax. Your formula should now look like this: =SORTBY(A2:A10, B2:B10).
  7. Press Enter. Excel will calculate the formula and return the sorted list of items based on the associated numbers. The items will be ordered from the lowest number in column B to the highest.
  8. Drag the fill handle (the small square in the bottom-right corner of the cell) down to copy the formula to as many cells as you have data rows.

Sorting in Descending Order

To order the numbers from largest to smallest, you can add a third argument to the SORTBY function. This argument allows you to specify the sort direction.

  1. Edit the formula in the cell where you initially entered =SORTBY(A2:A10, B2:B10).
  2. Add the sort direction. Type a comma after the closing parenthesis of your sort by array. Then, type FALSE or 1. For example: =SORTBY(A2:A10, B2:B10, FALSE).
  3. Press Enter. The list will now be sorted in descending order, placing the highest numbers at the top of the list.

Sorting by Multiple Columns

You can sort by more than one column of numbers. The formula works by sorting by the first sort key, and then applying secondary sorts to any tied values.

  1. Edit your formula.
  2. Add additional sort arrays. Separate each new sort array with a comma. For instance, if you want to sort by a date in column C first, and then by a number in column B, your formula would be: =SORTBY(A2:A10, C2:C10, FALSE, B2:B10, FALSE).
  3. Press Enter. The data will first be sorted by the date in column C, from newest to oldest. For any items that share the same date, they will be sorted by the number in column B.

Common Mistakes

  • Not using structured references: If you are using modern Excel and your data is an official Table (created via Insert > Table), you can use table references like =SORTBY(Table1[Item], Table1[Value]). This makes the formula much more readable and prevents errors if you add or remove rows.
  • Forgetting the comma separator: When adding a sort direction argument, you must separate it from the sort array with a comma, not a space.
  • Sorting text as numbers: If you attempt to sort a range of numbers that are actually stored as text (e.g., numbers formatted with a leading apostrophe like '123), the formula will treat them as text. Sorting text will place numbers before letters, and the order will not be numerical. You must ensure the numbers are in a number format before sorting.
  • Sorting by a single cell: The SORTBY function requires an array. If you select a single cell, such as B2, instead of a range like B2:B10, the formula will return a single value or a spill error. Always select the entire column or row of data you want to sort by.