Sort values in parallel (array formula)
Table of contents
- How to sort a table by Column 1 and then by Column 2 (array formula)
- How to sort a table by Column 1 and then by Column 2 (Right-click / Sort /Custom sort...)
1. How to sort a table by Column 1 and then by Column 2 (array formula)
Array formula in E2:
=INDEX(Descr, MATCH(SMALL(COUNTIF(Descr, "<"&Descr), ROW(1:1)), COUNTIF(Descr, "<"&Descr), 0)) + CTRL + SHIFT + ENTER copied down as far as needed.
Array formula in F2:
=INDEX(Qty, MATCH(SMALL(COUNTIF(Descr, "<"&Descr)+(1/(COUNTIF(Qty, ">"&Qty)+1)), ROW(1:1)), COUNTIF(Descr, "<"&Descr)+(1/(COUNTIF(Qty, ">"&Qty)+1)), 0)) + CTRL + SHIFT + ENTER copied down as far as needed.
Named ranges
Descr (B2:B15)
Qty (B2:B15)
What is named ranges?
Download excel sample file for this tutorial
Array formula sorts values in parallel.xls
(Excel 97-2003 Workbook *.xls)
Functions in this article:
IF(logical_test;[value_if:true];[value_if_false])
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE
INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range
SMALL(array,k) returns the k-th smallest row number in this data set.
ROW(reference) returns the rownumber of a reference
MATCH(lookup_value;lookup_array; [match_type])
Returns the relative position of an item in an array that matches a specified value
COUNTIF(range,criteria)
Counts the number of cells within a range that meet the given condition
2. How to sort a table by Column 1 and then by Column 2 (Right-click / Sort /Custom sort...)
- Select range (B2:B15)
- Right click and select sort
- Click Custom sort..

- Sort by "Description" and values from A to Z
- Then by "Qty" and values from smallest to largest
- Click ok.
External resources:
Sorting arrays in parallel (VBA)
Related posts:
- Filter unique rows and sort by date using array formula in excel
- Sort text values by length using array formula in excel
- Filter duplicate rows and sort by date using array formula in excel
- Sort a range by occurence using array formula in excel
- Filter duplicates from two columns combined and sort from A to Z using array formula in excel
- Sort dates within a date range using excel array formula
- Sort a range from A to Z using array formula in excel
- Sort text cells alphabetically from two columns using excel array formula
- Extract largest values from two columns using array formula in excel
- Filter text values existing in range 1 but not in range 2 using array formula in excel



February 1st, 2010 at 5:45 am
Oscar,
In the part of the formula: 1/(COUNTIF(Qty,">"&Qty)+1))
What is the purpose or logic for divide 1 by the countif (Qty,....)
and
what is the reason for the +1 par of the same formula?
thanks,
Chrisham
February 2nd, 2010 at 9:34 pm
chrisham,
Sorry for the late answer.
What is the purpose or logic for divide 1 by the countif (Qty,....)?
The purpose is to sort and find the right "Qty" value for each "Description" value. I know this is a short answer but use "Evaluate Formula" to see each step in formula calculation.
what is the reason for the +1 par of the same formula?
COUNTIF(Qty, ">"&Qty) returns an array containing a zero. 1/0 returns an error. So I had to add 1 to the whole array.