• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Excel SORTBY Function

You are here: Home / Excel Functions / Excel SORTBY Function

The Excel SORTBY function sorts the contents of a range or array based on the values in a corresponding range or array.  It can sort by multiple columns.  The syntax is:

=SORTBY(array, by_array1, [sort_order1], [[by_array2], [sort_order2]],…)

array is the range or array containing the values you want sorted.

by_array1 is the array or range to sort on.

sort_order1 is optional. It’s a number; 1 for ascending and -1 for descending. If omitted, it will sort in ascending order.

by_array2 is a second optional array or range to sort on.

sort_order2 is optional sort order for the second by_array. Use 1 for ascending and -1 for descending. If omitted, it will sort in ascending order.

Note: The SORTBY function is part of the new Excel Dynamic Arrays family. At the time of writing, Dynamic Arrays are only available in Office 365 and are currently in beta on the Insiders channel. Excel 2019 will not have the Dynamic Array functions.

Excel SORTBY Function Examples

Let’s say we want to sort the table in cells B17:D25 by the employee’s Start Date and then by Salary in ascending order. We can do this easily using the SORTBY Function as shown below:

Excel SORTBY function example

Sort Randomly

We can use the RANDARRAY function, which is another of the new dynamic array functions, to randomly sort a list. This could be used as an alternative to randomly drawing names out of a hat, as shown in the example below:

sort randomly

Note: The 9 in the RANDARRAY tells it to return 9 random numbers between 0 and 1.

The bonus with this solution is there are no repeats.

Tip: The RANDARRAY function is volatile, so once you have your results be sure to copy and paste them as values, so they don’t keep changing every time you edit a cell etc.

Download the Workbook

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.
Please enter a valid email address.

Download the Excel Workbook. Note: This is a .xlsx file please ensure your browser doesn't change the file extension on download.

Related Tutorials

Excel FILTER Function Filter cells based on criteria.
Excel RANDARRAY Function Returns an array of random numbers between 0 and 1.
Excel SEQUENCE Function Returns list of sequential numbers that increment as specified.
Excel SORT Function Sort cells or arrays in ascending or descending order.
Excel UNIQUE Function Extract a unique or distinct list from a range or array.

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
 
  • About My Online Training Hub
  • Contact
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Copyright © 2023 · My Online Training Hub · All Rights Reserved

Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.

Download A Free Copy of 100 Excel Tips & Tricks

excel tips and tricks ebook

We respect your privacy. We won’t spam you.

x