## Search each column for a string each and return multiple records – AND logic

*Article updated on February 17, 2018*

**Question:**

Can expand this equation set into more than two colums of data, say if I had a first, middle and last name column could I only display the values in which all three cases are true?

*This blog article answers a question in this article: Lookup with multiple criteria and display multiple search results using excel formula*

**Answer:**

**Table of Contents**

Lookup with multiple criteria and display multiple search results using excel formula

Lookup with multiple criteria and display multiple search results(vba)

### Array formula in E9:

### Download Excel *.xlsx file

multiple-criteria-lookup-with-multiple-results-2v3.xlsx

**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

**ROW(**reference**)** returns the rownumber of a reference

**COUNT(**value1, [value2]**)
**Counts the number of cells in a range that contain numbers

**SMALL(**array, k**)** returns the k-th smallest number in this data set.

**ISNUMBER(**value)

Checks whether a value is a number and returns TRUE or FALSE

**SUM(**number1, [number2], ... **)
**Adds all the numbers in a range of cells

**SEARCH()** Returns the number of the character at which a specific character or text string is first found, reading left to right (not case sensitive)

*This blog article is one out of five articles on the same subject.*

- Search for a cell value in an excel table
- Search for a text string in an excel table
- Lookup with multiple criteria and display multiple search results using excel formula
- Lookup with multiple criteria and display multiple search results using excel formula, part 2
- Lookup with multiple criteria and display multiple search results using excel formula, part 3

*Read more related articles in the archive.*

### Lookup with multiple criteria and display multiple search results (VBA)

**Where to copy vba code**

- Copy vba code below
- Press Alt + F11
- Insert a new module
- Paste code into code window
- Return to Excel

**Array Formula in cell E9:**

=Searchtbl(F2:F4;A2:C16)

**How to create array formula**

- Select cell range E9:G11
- Type above array formula
- Press and hold Ctrl + Shift
- Press Enter once
- Release alla keys

Function Searchtbl(SrchRng As Variant, tbl As Variant) As Variant 'SrchRng must have equal number of cells as headers in table Dim i, r, c As Single Dim tempArray() As Variant ReDim tempArray(tbl.Columns.Count - 1, 0) tbl = tbl.Value SrchRng = SrchRng.Value For r = LBound(tbl, 1) To UBound(tbl, 1) i = 0 For c = LBound(SrchRng) To UBound(SrchRng) If InStr(UCase(tbl(r, c)), UCase(SrchRng(c, 1))) = 0 Then i = 0 Exit For Else i = i + 1 End If Next c If i = UBound(tbl, 2) Then For c = LBound(tempArray, 1) To UBound(tempArray, 1) tempArray(c, UBound(tempArray, 2)) = tbl(r, c + 1) Next c ReDim Preserve tempArray(UBound(tempArray, 1), UBound(tempArray, 2) + 1) i = 0 End If Next r ReDim Preserve tempArray(UBound(tempArray, 1), UBound(tempArray, 2) - 1) Searchtbl = Application.Transpose(tempArray) End Function

**Download excel file *.xls**

multiple-criteria-lookup-with-multiple-results-vba.xls

### Read more articles about this topic

The following article shows you how to VLOOKUP and return multiple values, the lookup value must match the entire cell value.

5 easy ways to VLOOKUP and return multiple values

This post explains how to lookup a value and return multiple values. No array formula required.

Search for a cell value in a dataset:

Search for a cell value in a dataset

This blog article is one out of five articles on the same subject. Search for a cell value in an […]

How to look for values in a column that contain two text strings:

Search for multiple text strings in multiple cells

Question: How do I search a list for two text strings and return a list with where both strings occurs? […]

Search two columns for two text strings. The strings can be anywhere in these two columns but both text strings have to be found in different cell values or a single cell value and be on the same row to match:

A record is returned if both search strings are found on the same row

Question: I want to search two columns with two search strings? The strings can be anywhere in these two columns […]

Search for three text strings in three columns, one text string in each column. Return values in which all three cases are found:

Search each column for a string each and return multiple records – AND logic

Question: Can expand this equation set into more than two colums of data, say if I had a first, middle […]

Search for **multiple text strings** in **multiple columns**, one text string in each column. Return values in which **all text strings match**:

Extract records where all criteria match if not empty

Question: I second G's question: can this be done for more than 3? i.e. (Instead of last name, middle, first) […]

Search for a single text string in a **single** column and return multiple matches.

Search for a text string and return multiple adjacent values

This article demonstrates array formulas that search for cell values containing a search string and returns corresponding values on the […]

Search for a text string in a **single** column and return multiple corresponding values.

Search for a text string and return multiple adjacent values

This article demonstrates array formulas that search for cell values containing a search string and returns corresponding values on the […]

Search for multiple text strings in a **single** column and return multiple corresponding values.

Search for a text string and return multiple adjacent values

This article demonstrates array formulas that search for cell values containing a search string and returns corresponding values on the […]

Search for a text string in **multiple** columns and return corresponding values.

Search for a text string and return multiple adjacent values

Lookup and return multiple values concatenated into one cell

This article demonstrates how to find a value in a column and concatenate corresponding values on the same row. The […]### 16 Responses to “Search each column for a string each and return multiple records – AND logic”

### Leave a Reply

**How to add a formula to your comment:**

<code>your formula</code>

**How to add VBA code to your comment:**

[vb 1="vbnet" language=","]

VBA code

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org

Add picture link to comment.

**Contact Oscar**

You can contact me through this webpage

You are a genius. Formulas are simple, and easy to understand.

Could this be done to filter for 10 criteria?

10 criteria in each column? 10 criteria in all columns?

Hi,

i had a similar query and i believe your example is the way forward for me but i can't get my search to work.

like your example i'm searching 3 columns but in a table of 8 colums and the search function is on a seperate tab. there is also a gap between the columns i'm searching. i also decided not to name the ranges as they may change. are any of the above affecting the formala or is it just me?

ignore my last comment... it works a treat!! (i put in one too many $ signs!!)

Thanks!

I second G's question: can this be done for more than 3?

i.e.

(Instead of last name, middle, first)

customer#, cust name, appt date, appt time, venue, coordinator, assistant

Thanks for putting this up!

D,

See this blog post: https://www.get-digital-help.com/2009/10/01/lookup-with-multiple-criteria-and-display-multiple-search-results-using-excel-formula-part-4/

I applied this in my spreadsheet and worked perfectly well.

However, I noticed that if a cell in the search range is blank, it does not include it in the results. In your example, if B2 was blank instead of having the value "Ted." that name would not show up in the search results (E9:E11).

Is there a work around for this? The spreadsheet I have may have blank cells but I need them to show in the results page.

Thanks!!!

THis is great!!!

What if I want to search using 4 criteria? Can you please help me?

Thanks!

Min,

I have changed the formula. I think the new formula is easier. I have also written an explanation, perhaps with help from explanation, you can now add a fourth criterion yourself? Otherwise, comment here again.

I uploaded a new file, as well.

Hi,

Your articles are really helpful! Can you please suggest if i want to find out the rows with fixed value in "First Name" but, if either of the criteria for "Middle Name" or "Last Name" will suffice. Also, i don't want repeated values in the final sheet.

For eg:

FN: a

MN: o

LN: o

Then, Davydenko Roy Nikolay should come only once.

Regards

RU,

Read this post: Lookup with multiple criteria and display multiple unique search results (array formula)

This solution was elegant and consistent! The only issue I am facing, (or so I've been told by an associate) is that as the number of entries increases, it would be best to write this functionality into a module(?) for the sake of performance. Any ideas, solutiobns or resources would be appreciated!! Thank you!!

Jim,

I have added a custom function to this post. I have not done any performance testing.

Oscar = Legend / Demigod

Thanks for your time and skill explaining this for all us mortals.

Stuart,

Thank you for commenting!

The explanations are not that hard to do. Select a cell containing a formula. Click in the formula bar. Press F9 and the formula is converted into a value. This also works for array formulas.