Spreadsheet Practice

How to categorize transactions by keywords in Excel

Excel formula

=XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$7,A2)),$F$2:$F$7,"Uncategorized")

Keep keywords and categories in a table and return the category of the first keyword found: =XLOOKUP(TRUE,ISNUMBER(SEARCH(keywords,A2)),categories,"Uncategorized").

Result on the example
one result per row in C2, filled down to C8
Works in
Excel 2021, 2024 and Microsoft 365
Google Sheets
Different formula, see below

See it work

The formula is already in C2, filled down to C8. Change any input and the result updates, or edit the formula to experiment.

How it works

SEARCH checks the description for every keyword at once, and ISNUMBER marks the ones found as TRUE. XLOOKUP finds the first TRUE and returns the category from the same row. Because it takes the first match, "uber eats" sits above "uber" in the table, so Uber Eats is a meal and an Uber trip is travel.

=XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$7,A2)),$F$2:$F$7,"Uncategorized")

Result"Travel"

  1. $E$2:$E$76 rows × 1 col: "uber eats", "uber", "amazon web", "delta air", …

    A range: 6 cells in one column.

  2. A2"UBER *TRIP 8812"

    The value in A2.

  3. SEARCH($E$2:$E$7,A2){6 rows × 1 col} #VALUE!, 1, #VALUE!, #VALUE!, …

    SEARCH: Position of text, not case-sensitive, allows wildcards.

    • find_text$E$2:$E$76 rows × 1 col: "uber eats", "uber", "amazon web", "delta air", …
    • within_textA2"UBER *TRIP 8812"
  4. ISNUMBER(SEARCH($E$2:$E$7,A2)){6 rows × 1 col} FALSE, TRUE, FALSE, FALSE, …

    ISNUMBER: TRUE if the value is a number.

    • valueSEARCH($E$2:$E$7,A2){6 rows × 1 col} #VALUE!, 1, #VALUE!, #VALUE!, …
  5. $F$2:$F$76 rows × 1 col: "Meals", "Travel", "Software", "Travel", …

    A range: 6 cells in one column.

  6. XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$7,A2)),$F$2:$F$7,"Uncategorized")"Travel"

    XLOOKUP: Searches one range and returns the matching item from another.

    • lookup_valueTRUE
    • lookup_arrayISNUMBER(SEARCH($E$2:$E$7,A2)){6 rows × 1 col} FALSE, TRUE, FALSE, FALSE, …
    • return_array$F$2:$F$76 rows × 1 col: "Meals", "Travel", "Software", "Travel", …
    • if_not_found"Uncategorized"

In Google Sheets

Google Sheets needs a different formula: =ARRAYFORMULA(XLOOKUP(TRUE,ISNUMBER(SEARCH($E$2:$E$7,A2)),$F$2:$F$7,"Uncategorized")). On the same data it gives the same result. Here it is running in Google Sheets mode.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=IFERROR(INDEX($F$2:$F$7,MATCH(TRUE,ISNUMBER(SEARCH($E$2:$E$7,A2)),0)),"Uncategorized")Travel, Software, Travel…For Excel 2019 and earlier. In Excel 2016 and older, confirm it with Ctrl+Shift+Enter.

Common mistakes

  • Order matters: put specific keywords above general ones, or "uber" claims every Uber Eats charge.
  • An empty row inside the keyword range matches every description. Size the range to the filled rows, or use an Excel Table.
  • Very short keywords ("air") match inside unrelated words. Use distinctive text.

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.

Categorize transactions by keywords

In C2, return the category of the first keyword in E2:E7 that appears in the description, or "Uncategorized" if none does. Fill down to C8.

Questions

How do I total spending per category?

SUMIF on the new column: =SUMIF(C2:C8,"Travel",B2:B8).

Can the match be case-sensitive?

Use FIND instead of SEARCH.

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.