The Google Sheets function SORT is essential for organizing data efficiently. It enables users to order rows of a specified array or range according to the values in designated columns, facilitating better data analysis and presentation. Whether you are working with simple lists or complex datasets, mastering the SORT function can significantly enhance your spreadsheet capabilities.
Syntax
SORT(range, sort_index, sort_order, [by_col])
- range: The array or range of data you want to sort.
- sort_index: The column number (or row number, if by_col is TRUE) to sort by.
- sort_order: A numerical value, where 1 indicates ascending order and 0 indicates descending order.
- by_col: (Optional) A BOOLEAN value that, if TRUE, sorts by column; if FALSE or omitted, sorts by row.
Example #1
SORT(A2:C10, 2, TRUE)
This function sorts the range from A2 to C10 based on the values in the second column in ascending order. For example, if column B contains names sorted to show alphabetical order: Alice, Bob, Charlie.
Example #2
SORT(A2:C10, 1, FALSE)
Here, the function sorts the range A2 to C10 by the first column in descending order. For instance, if column A contains numbers, this may result in: 100, 90, 80, etc.
Example #3
SORT(A2:C10, 3, TRUE, TRUE)
This variant sorts the data by the third column in ascending order while also treating the input data as columns. Thus, if column C lists sales figures, you would see the sales organized from lowest to highest.
Error handling
- REF!: This error arises if a specified range or column does not exist. Ensure the range is valid and correctly referenced.
- VALUE!: This indicates that the data type is not compatible with the sort. Check if the sort_index corresponds correctly to a column/row number within the specified range.
- N/A: This error implies that the function cannot find the specified criteria for sorting. Verify the sort parameters to ensure they are correct.