Use VLOOKUP and return multiple values sorted from A to Z
This article demonstrates how to extract multiple values based on a search value and display them sorted from A to Z.
The array formula in column G filters values in column C using a condition in cell E3, comparing it with values in adjacent column B. The filtered values are then sorted from A to Z.
It is possible to build a formula around the VLOOKUP function but it would be big, the following formula is smaller and easier to understand.
Table of Contents
1. Extract multiple values based on a search value sorted from A to Z
This example demonstrates a formula that works in most Excel versions. The formula in cell G3 extracts values from column C if the corresponding value on the same row matches the search value specified in cell E3.
The result is sorted from A to Z and displayed in cell G3 and cells below as far as needed.
Array formula in cell G3:
1.1 Watch a video where I explain the formula
Recommended article
Recommended articles
This article demonstrates how to extract unique distinct values based on a condition and also sorted from A to z. […]
1.2 How to enter an array formula
- Double press with the left mouse button on cell G3.
- Copy and paste the above formula to cell G3.
- Press and hold CTRL + SHIFT simultaneously.
- Press Enter once.
- Release all keys.
Take a look at the formula bar and you will see that the formula now has a beginning and ending curly bracket.
Don't enter these characters yourself, they appear automatically. Example, {=array_formula}
The image above demonstrates the location of the formula bar.
Recommended article
Recommended articles
Array formulas allows you to do advanced calculations not possible with regular formulas.
1.3 Explaining formula in cell G3
Step 1 - Sort values in column C
COUNTIF($C$3:$C$10, "<"&$C$3:$C$10)
becomes
COUNTIF({"F"; "S"; "G"; "E"; "B"; "N"; "W"; "A"},{"<F"; "<S"; "<G"; "<E"; "<B"; "<N"; "<W"; "<A"})
and returns
{3;6;4;2;1;5;7;0}
Recommended article
Recommended articles
Counts the number of cells that meet a specific condition.
Step 2 - Extract sort rank numbers for chosen category
IF($E$3=$B$3:$B$10, COUNTIF($C$3:$C$10, "<"&$C$3:$C$10), "")
becomes
IF($E$3=$B$3:$B$10, {3;6;4;2;1;5;7;0}, "")
becomes
IF($E$3=$B$3:$B$10, {3;6;4;2;1;5;7;0}, "")
becomes
IF(1={1;2;1;2;1;1;2;2},{3;6;4;2;1;5;7;0},"")
becomes
IF({TRUE;FALSE;TRUE;FALSE;TRUE;TRUE;FALSE;FALSE},{3;6;4;2;1;5;7;0},"")
and returns
{3;"";4;"";1;5;"";""}
Recommended article
Recommended articles
Checks if a logical expression is met. Returns a specific value if TRUE and another specific value if FALSE.
Step 3 - Find k-th smallest value in array
SMALL(IF($E$3=$B$3:$B$10,COUNTIF($C$3:$C$10,"<"&$C$3:$C$10),""),ROWS($A$1:A1))
becomes
SMALL({3;"";4;"";1;5;"";""},ROWS($A$1:A1))
becomes
SMALL({3;"";4;"";1;5;"";""},1)
and returns 1.
Recommended article
Recommended articles
The SMALL function lets you extract a number in a cell range based on how small it is compared to the other numbers in the group.
Step 4 - Match sort rank to find relative position
MATCH(SMALL(IF($E$3=$B$3:$B$10, COUNTIF($C$3:$C$10, "<"&$C$3:$C$10), ""),ROWS($A$1:A1)), COUNTIF($C$3:$C$10,"<"&$C$3:$C$10), 0)
becomes
MATCH(1, {3;6;4;2;1;5;7;0}, 0)
and returns 5.
Recommended article
Recommended articles
Identify the position of a value in an array.
Step 5 - Return values
INDEX($C$3:$C$10,MATCH(SMALL(IF($E$3=$B$3:$B$10,COUNTIF($C$3:$C$10,"<"&$C$3:$C$10),""),ROWS($A$1:A1)),COUNTIF($C$3:$C$10,"<"&$C$3:$C$10),0))
becomes
INDEX($C$3:$C$10,5)
becomes
INDEX({"F";"S";"G";"E";"B";"N";"W";"A"},5)
and returns B in cell G3.
Recommended article
Recommended articles
Gets a value in a specific cell range based on a row and column number.
Tip! You can easily filter values if you convert your data to an excel table and then sort them:
Recommended articles
An Excel table allows you to easily sort, filter and sum values in a data set where values are related.
2. Extract multiple values based on a search value sorted from A to Z (Excel 365)
This example demonstrates a regular formula that works only in Excel 365. The formula is a dynamic array formula in cell G3, it returns multiple values that spills to cells below automatically.
It contains two functions, the FILTER function and the SORT function. It extracts values from column C if the value on the same row in column B matches the search value specified in cell E3.
Formula in cell G3:
2.1 Explaining formula
Step 1 - Filter values based on a condition
The FILTER function extracts values/rows based on a condition or criteria.
FILTER(array, include, [if_empty])
FILTER(C3:C10,E3=B3:B10)
becomes
FILTER({"F"; "S"; "G"; "E"; "B"; "N"; "W"; "A"}, 1={1; 2; 1; 2; 1; 1; 2; 2})
becomes
FILTER({"F"; "S"; "G"; "E"; "B"; "N"; "W"; "A"}, {TRUE; FALSE; TRUE; FALSE; TRUE; TRUE; FALSE; FALSE})
and returns {"F"; "G"; "B"; "N"}.
Step 2 - Sort result
The SORT function lets you sort values from a cell range or array.
SORT(array, [sort_index], [sort_order], [by_col])
SORT(FILTER(C3:C10,E3=B3:B10))
becomes
SORT({"F"; "G"; "B"; "N"})
and returns {"B"; "F"; "G"; "N"}.
Vlookup and return multiple values category
This post explains how to lookup a value and return multiple values. No array formula required.
Question: How do i return multiple results for one lookup value? I have tried to use multiple vlookups, with no […]
VLOOKUP and return multiple matches based on many criteria.
Excel categories
2 Responses to “Use VLOOKUP and return multiple values sorted from A to Z”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Hii Oscar
I have a problem and I know you can help me definitely
"Am your way the great ..." this values with space in one cell (B1)
Is there any formula to seperate all strings in one raw like
C1- Am
C2- your
C3- way
C4- the
C5- great
C6-
C7-
Etc.
Anil
Yes there is but the formula is large:
https://www.get-digital-help.com/2011/03/23/text-to-columns-split-words-in-a-cell-excel-array-formula/
I recommend Rick Rothstein (MVP - Excel)'s formula:
https://www.get-digital-help.com/2011/03/23/text-to-columns-split-words-in-a-cell-excel-array-formula/#comment-52519