How you can use wildcards with the XLOOKUP() operate in Excel

hand indicate spreadsheet on the screen with pen
Picture: Luca Lorenzelli/Adobe Inventory

Lookup features are nice for locating values that match one other worth. Because of XLOOKUP() this job is less complicated than ever, and it even helps wildcards! On this article, I’ll present you the best way to use the asterisk wildcard (*) to create a extra versatile lookup worth. As a substitute of discovering an actual or virtually match, dropping in a wildcard permits you to work with a less complicated search string. This setup is useful whenever you keep in mind a part of the search string, however not all of it. On this article, I’ll present you the best way to use a wildcard within the XOOKUP() operate’s standards argument, or search string.

SEE: Software program Set up Coverage (TechRepublic)

You possibly can use VLOOKUP(), protecting a couple of issues in thoughts: You will need to restructure the supply information as a result of the return worth is to the left of the lookup worth, and VLOOKUP() can’t deal with that. I’m utilizing XLOOKUP() going ahead although. Except I run into a particular motive to make use of one of many older lookup features, I see no benefit to utilizing them. In the event you’d prefer to find out about XLOOKUP(), learn How you can use the newish XLOOKUP() dynamic array operate in Excel.

I’m utilizing Microsoft 365 on a Home windows 10 64-bit system. Excel’s XLOOKUP() operate is accessible in Microsoft 365 and Excel 2021, and Excel for the online. On your comfort, you’ll be able to obtain the demonstration .xlsx information. This text assumes that you’ve primary Excel abilities, however even a newbie ought to be capable to comply with the directions to success.

Setting issues up

Let’s suppose that you simply use Excel to trace merchandise for a gourmand meals distributor. As you’ll be able to see in Determine A, the product names are a bit advanced, and it may be troublesome to recollect them precisely. When looking out, you may think about filtering or supplying a knowledge validation management, however in each circumstances, the product checklist is lengthy and a bit awkward to work with. The following step may be to make use of XLOOKUP(), which returns a single worth primarily based on a lookup worth—on this case, the product names as follows:


=XLOOKUP($I$2,$D$3:$D$47, $C$3:$C$47)

You will need to enter the total product identify. As an example, should you attempt to discover “Uncle Bob’s Natural Dried Pears” by getting into solely Pears you’ll be disillusioned (Determine A). (Bear in mind, should you’re not utilizing a Desk object, your references gained’t look the identical as a result of Desk objects use construction referencing.)

Determine A

We’ll need wildcards to find some products by product name.
We’ll want wildcards to search out some merchandise by product identify.

The error worth is an effective clue; #N/A way the operate can’t discover the worth in I2. In the event you see a #VALUE error, one thing’s incorrect with the operate itself. In the event you paste the worth from column D into I2, the operate works as anticipated, so you realize it’s the enter worth and never the operate. There’s no thriller concerned. XLOOKUP() needs an actual match, and the present setup can’t get the job achieved. Nevertheless, throwing a wildcard into the combo can!

How you can add a wildcard in Excel

Don’t fear should you’re not acquainted with wildcards, however they’re one thing you need to evaluate as a result of they actually turn out to be useful. We’ll be utilizing the asterisk character (*), which finds any variety of characters. For instance, to search out all the product identify utilizing solely pears as a lookup worth, you’d use *pears* because the search string.

You’ll be able to’t simply plug within the asterisk character although. When including wildcards to a operate on this approach, you need to concatenate the delimiter and the reference. Inside this context, concatenation means to mix parts that Excel evaluates into one string and delimiter is a personality that helps within the course of by figuring out the info sort. We’ll use the greenback signal character ($) to mix parts.

Now, let’s look again on the unique XLOOKUP()


$I$2 identifies the lookup worth, Table2[ProductName] is the column the lookup worth must match, and Table2[UnitPrice] is the return worth when a match is discovered. In plain English, this operate returns the worth from the UnitPrice column the place the ProductName worth matches the worth in I2.

The one modification we have to make is to the lookup worth, $I$4. Particularly, we have to add two wildcards and use the double citation characters as string delimiters

"*" & $I$4 & "*"

which consider to *$!I$4*. The string delimiters across the asterisk characters are required. The modified operate

=XLOOKUP("*"& $I$4 &"*",Table2[ProductName],Table2[UnitPrice],2,2)

handles the wildcard appropriately, as proven in Determine B.

=XLOOKUP("*"& $I$4 &"*",Table2[ProductName],Table2[UnitPrice],2,2)

Determine B

XLOOKUP() returns a match using the * wildcard.
XLOOKUP() returns a match utilizing the * wildcard.

The one factor I need to level out is that this operate returns a single worth. Attempt getting into Sir into I4. As you’ll be able to see in Determine C, the operate returns $81, matching Sir Rodneys’ Marmalade in D21. Do you see the issue? The worth in D22 additionally comprises the string Sir. That is the one hitch that may be an issue.

Determine C

If you have duplicates, you might want to alert users.
In case you have duplicates, you may need to alert customers.

A warning about duplicates in Excel
When utilizing XLOOKUP() to discover a single worth, you need to use a wildcard as proven, however the risk exists that the operate may not return the precise worth if the search string exists in a couple of worth. For that reason, you may need to alert the person that different matching information exist.

We are able to method this alert in a lot of other ways, however the easiest methodology is to make use of conditional formatting. On this case, we have to alert the person when the search string matches two or extra information. First, we have to resolve what to focus on: The leads to J4 or the precise merchandise. You possibly can do both or do each. We’ll do the previous utilizing the next expression

=COUNTIF(Table2[ProductName],"*" & $I$4& "*")>1

in cell K4. This operate returns TRUE if the search string (at the moment Sir) happens greater than as soon as within the ProductName column and FALSE if not. In the event you want that customers not see this helper operate, scale back the column width and even cover the column (I don’t actually advocate the latter as a result of features are simple to overlook and discover later.) Now you’re able to create the conditional formatting rule:

  1. Choose I4:J4. On the House tab, click on Conditional Formatting within the Kinds group and select New Rule from the ensuing dropdown.
  2. Within the high pane of the ensuing dialog, click on Use a System to Decide Which Cells to Format the management within the backside pane, enter
  3. Click on Format.
  4. Click on the Font tab, select a shiny eye-catching coloration, reminiscent of crimson from the Coloration dropdown, after which click on OK. Determine D reveals the operate and the format.
  5. Click on OK to return to the sheet. Discover that the rule makes use of the crimson font for Sir and $81 as a result of the search string, Sir, happens a couple of within the ProductName column.

Determine D

Use this conditional formatting rule to highlight the search string.
Use this conditional formatting rule to focus on the search string.

In the event you’re the one one who makes use of the sheet, you’ll be able to cease right here. It’s unlikely you’ll want a reminder as to what the spotlight means. At this level, discovering the duplicates within the identify column is a fast Discover job. Merely drop *Sir* into the Discover What management.

Source link

Be the first to comment

Leave a Reply

Your email address will not be published.