How to assign a category when a cell contains a keyword from a list
Formula (Excel and Google Sheets)
=XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$8,A2)),$F$2:$F$8,"Other")Search the cell for every keyword and return the category of the first one found: =XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$8,A2)),$F$2:$F$8,"Other").
- Result on the example
- one result per row in
C2, filled down toC9 - Works in
- Excel 2021, 2024 and Microsoft 365
- Google Sheets
- Same formula
See it work
The formula is already in C2, filled down to C9. Change any input and the result updates, or edit the formula to experiment.
How it works
SEARCH($E$2:$E$8,A2) looks for every keyword in the description at once and returns a position where it is found and #VALUE! where it isn't. ISNUMBER turns that into TRUE and FALSE, and XLOOKUP returns the category beside the first TRUE. SEARCH ignores case, so "uber" finds "UBER".
=XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$8,A2)),$F$2:$F$8,"Other")Result"Transport"
$E$2:$E$87 rows × 1 col: "uber", "lyft", "starbucks", "shell", …A range: 7 cells in one column.
A2"UBER *TRIP 8841"The value in A2.
SEARCH($E$2:$E$8,A2){7 rows × 1 col} 1, #VALUE!, #VALUE!, #VALUE!, …SEARCH: Position of text, not case-sensitive, allows wildcards.- find_text
$E$2:$E$87 rows × 1 col: "uber", "lyft", "starbucks", "shell", … - within_text
A2"UBER *TRIP 8841"
- find_text
ISNUMBER(SEARCH($E$2:$E$8,A2)){7 rows × 1 col} TRUE, FALSE, FALSE, FALSE, …ISNUMBER: TRUE if the value is a number.- value
SEARCH($E$2:$E$8,A2){7 rows × 1 col} 1, #VALUE!, #VALUE!, #VALUE!, …
- value
$F$2:$F$87 rows × 1 col: "Transport", "Transport", "Coffee", "Fuel", …A range: 7 cells in one column.
XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$8,A2)),$F$2:$F$8,"Other")"Transport"XLOOKUP: Searches one range and returns the matching item from another.- lookup_value
TRUE - lookup_array
ISNUMBER(SEARCH($E$2:$E$8,A2)){7 rows × 1 col} TRUE, FALSE, FALSE, FALSE, … - return_array
$F$2:$F$87 rows × 1 col: "Transport", "Transport", "Coffee", "Fuel", … - if_not_found
"Other"
- lookup_value
In Google Sheets
The same formula works in Google Sheets: =XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$8,A2)),$F$2:$F$8,"Other"). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IFERROR(INDEX($F$2:$F$8,MATCH(TRUE,ISNUMBER(SEARCH($E$2:$E$8,A2)),0)),"Other") | Transport, Coffee, Fuel… | For Excel 2019 and earlier (Ctrl+Shift+Enter in 2016 and older). |
Common mistakes
- Short keywords match inside other words: "shell" would also tag "SHELLEY'S BAKERY". Make keywords specific, or put the more specific ones higher in the list.
- When two keywords match, the one higher in the keyword list wins.
- Lock the keyword ranges with
$before filling down.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Assign a category when a cell contains a keyword from a list
C2, return the category of the first keyword from E2:E8 that appears in the description, or "Other" if none does. Fill down to C9.Questions
How do I make the keyword match case-sensitive?
Use FIND instead of SEARCH.
How do I return the matched keyword itself?
Return the keyword column: =XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$8,A2)),$E$2:$E$8,"").
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.