ajSortArray function
Description
The ajSortArray function sorts the contents of a range or array.
Syntax
ajSortArray(in_array, [sort_index], [sort_order], [by_col], [convert_to_text])
Argument Name | Description |
---|---|
in_array (required) | The range of cells to be sorted. |
sort_index (optional) | Points to a specified column or row (depending on the value set in ‘By_col’) to be sorted. If you do not specify anything, the default value will always be 1. |
sort_order (optional) | 1 indicates sorting A to Z. 2 indicates sorting Z to A If you do not specify anything, the default value will always be 1. |
by_col (optional) | If it equals FALSE, the rows will be sorted according to the column index specified. If it equals TRUE, the columns will be sorted according to the row index specified. If you do not specify anything, the default value will always be FALSE. All values other than 0 and FALSE will be treated as TRUE. |
convert_to_text (optional) | If it equals TRUE, the return result will be converted to string values. If it equals FALSE, the return result will preserve the original data type but any string value that has more than 256 characters will cause an error. If you do not specify anything, the default value will always be FALSE. |
The function will return:
1) Content type: The sorted range of cells
2) Method: Cell array
Examples
Here are a few examples of ajSortArray function.
Example 1 (sort according to column index)
The function in this example sorts the range B2:E6 by the second column in ascending order.
As ‘convert_to_text’ is FALSE, the values in column Header2 and column Header4 are treated as numbers. Thus, their column sums are calculated correctly.
Example 2 (sort according to row index)
This is an example of sort by column. This function in this example sorts the range C22:F25 by the second row in descending order.
As ‘convert_to_text’ is TRUE, all values are treated as strings. Therefore, all row sums are 0.