## VLOOKUP with a single wildcard

Imagine we have this table of employee information and we’ve been given a partial name (in this example: “**Mye**“) to find and retrieve information about.

To do this we use a standard

formula with the wildcard asterisk character: **VLOOKUP*******

The idea here is that we’ll search through the **Last Name** column to find the one starting with “Mye”, even though we don’t know the full surname.

We use this formula to achieve that, e.g. to look up first name:

`=VLOOKUP(G$2&"*",$A$1:$D$51,2,FALSE)`

The `G$2&"*"`

searches for the string “Mye*” where the * is known as a wildcard and represents a string of anything, or nothing, that could follow on after “Mye”. In other words, it would match “Mye”, “Myers”, “Mye123”, “MyeABC123!@#”,…etc.

The rest of the formula is just a regular `VLOOKUP`

.

See the workbook here and feel free to make your own copy (**File > Make a copy…**).

## VLOOKUP with two wildcards

What if our partial match potentially has missing characters *before* as well as after it?

No problem! We can simply add a second wildcard in front of the partial match and proceed as before. The formula for first name becomes:

`=VLOOKUP("*"&G$2&"*",$A$1:$D$51,2,FALSE)`

Since the wildcard characters can also represent nothing (i.e. no characters), then it doesn’t matter if there turns out to be nothing in front of (or after) our partial string.

**Notes:**

- It’s necessary to use FALSE as the last argument of your VLOOKUP in order for the wildcard matching to work.
- If there are multiple matches on the wildcard string in your data table, then the first one is returned, same as the usual application of VLOOKUP.

The workbook with single and double wildcard lookups is available here.

Would it be plausible to use of wildcards to search a month using either QUERY or VLOOKUP or would it be easier to use LEFT and RIGHT to identify a specific value (say month or year) to search for?

Hey Aaron,

Must have missed this comment when you originally posted it!

Not sure exactly what you mean, but I haven’t tried a vlookup with a wildcard in a date (in place of a specific day?). It’s probably doable. Another option would be to use a query and specify that the date lie between a start date (end of prior month) and an end date (first day of the future month).

Ben

How can I do a wildcard, but only for certain amount of characters? Kinda like “match anything, but only if it’s under 6 characters”, not like wildcard, which would match from 0 to 1000000 characters.

Hi,

With the data from this example, you could use a formula like this to return everything where the Last Name is 6 characters or less:

`=ArrayFormula(query(if(len(A2:A51)< =6,A2:D51,""),"select * where Col1 is not null",0))`

Hope that helps!

Ben

Nice tip Ben. You saved me again.

cheers

Mike

As the information from Google forms is stored in a new line below the preexisting information, I would like to make an upward vertical lookup, in order to find the most recent information in case a value appearse more than once in the column. How can I achieve this?

Hi Rafael,

It’s a little more complicated if you have multiple values in your lookup column, and I don’t have an example on this site. See if this helps: http://infoinspired.com/google-docs/spreadsheet/find-nth-occurrence-in-google-sheets/

Cheers,

Ben

This is great, but I am looking for the opposite. I want to have a lookup table where the partial text is in the first column and it checks to see if that text is contained in the source cell.

For example, the lookup table would have “St.” in the first column and “Street” in the second column, cell A1 would contain “Jones St.” and the VLOOKUP would return “Street” when it points to cell A1.

Is this possible?

This is why I’m here too! 🙂

Exact same for me as well. Any solution so far…?

How would I accomplish this if the data is on a separate tab? Thank you any help is appreciated.

Y’all should absolutely look at the Flookup add-on.

It’s versatile and holds up really well in handling approximate match cases.

Hi Ben,

Great info as usual. Wondering if there is a way to make this work with arrays.

Wondering if you might be able to help me figure out a way to make this array formula work? I can make it work if the SEARCH function > text_to_search argument is a single cell, but not if it’s an array. I want it to be an array so it auto-applies to any new row added to the spreadsheet.

Below works (note A2 in the SEARCH function). Cell C2 on Raw Data tab.

=INDEX(Validations!A:B,MATCH(TRUE,ISNUMBER(SEARCH(Validations!A:A,A2)),0),2)

Below doesn’t work (note A2:A in SEARCH). The array formula expands to all new cells, but the returned values are blank. If I change the bold A2:A to just A2, it always returns the value for cell A2’s match, not A3, A4, etc for each corresponding row.

=ArrayFormula(IF(ISBLANK(A2:A),””,INDEX(Validations!A:B,MATCH(TRUE,ISNUMBER(SEARCH(Validations!A:A,A2:A)),0),2)))

Seems like Index / Match doesn’t work with Arrays and now I found your post here I wonder if I could do it with vlookups of partial string matches like you have here, but as an array instead of just one value to vlookup.

Thanks so much.

Here is a link to the test data sheet. https://docs.google.com/spreadsheets/d/1slUiZdDKLNDRfismNj9B7_YAhcQuIJBW4JBcEa8l2UE/edit?usp=sharing

Hi Ben,

Thanks for this, the first wildcard instance works, but it fails to return the value when the wildcard is not needed?

Ie. if I’m searching for

“12345*”, it will return the value fine (it’s searching for

12345 A, or even 12345 B)

but if a plain 5 digit number like 12345 will return a #N/A error.

The reason for the need for the wildcard, is some items have just 5 digits, whilst some may have an A, B, C or even D added on after (with a space)

Thanks,

David