How to auto-categorize bank transactions in Excel using XLOOKUP and keyword tables
Excel, Sheets & tax prep · · 5 min read
Categorizing a few hundred bank transactions by hand every month is slow, and the descriptions keep changing: a store number here, a date or reference there. A small keyword table and one XLOOKUP formula does it for you. You write a rule once ("GUSTO" means Payroll) and every row that mentions it is categorized, this month and every month after.
Set up the keyword table
Add a sheet called Rules. Put a short keyword in column A and the category it stands for in column B:
| Keyword (A) | Category (B) |
|---|---|
| GUSTO | Payroll |
| AWS | Software |
| SHELL OIL | Vehicle |
| VERIZON | Phone |
| AMAZON | Supplies |
Keep keywords to the part of the description that never changes. "SHELL OIL" matches SHELL OIL 574412093 and SHELL OIL 88213 alike, where the full text would match
only one of them.
The formula
With your transactions on another sheet, descriptions in column B, add a Category column and put this in its first row:
=XLOOKUP(1, ISNUMBER(SEARCH(Rules!$A$2:$A$200, B2)) * (Rules!$A$2:$A$200<>""), Rules!$B$2:$B$200, "Uncategorized") Fill it down. Reading it from the inside out:
SEARCH(Rules!$A$2:$A$200, B2)looks for every keyword in the description at once. SEARCH ignores case, so "Amazon" and "AMAZON" both match.ISNUMBER(…)turns that into TRUE for the keywords found and FALSE for the rest.* (Rules!$A$2:$A$200<>"")rules out the empty rows below your last keyword. Without it, an empty keyword "matches" every description, and rows with no real match get a blank category instead of "Uncategorized".XLOOKUP(1, …)returns the category of the first keyword that matched, or "Uncategorized" when none did.
XLOOKUP needs Excel for Microsoft 365 or Excel 2021 or later. Google Sheets has XLOOKUP too; wrap
the formula in ARRAYFORMULA( ) there so SEARCH checks every keyword. In older Excel, =IFERROR(INDEX(Rules!$B$2:$B$200, MATCH(1, ISNUMBER(SEARCH(Rules!$A$2:$A$200, B2)) *
(Rules!$A$2:$A$200<>""), 0)), "Uncategorized") does the same job, entered with Ctrl+Shift+Enter.
Order the rules
The first keyword that matches wins, so put specific keywords above general ones. If "AMAZON" sits above "AMAZON WEB SERVICES", your AWS bill is filed under Supplies. Move the longer keyword up and both are categorized correctly.
Each month after that
- Paste or convert the new statement's transactions under the old ones.
- Fill the formula down to the new rows.
- Filter the Category column for "Uncategorized" to see merchants you have no rule for yet.
- Add a keyword for each one to the Rules sheet. Every past and future row updates.
After two or three months, most rows categorize themselves and the Uncategorized filter shows a handful of new merchants.
Start from a statement that adds up
Category totals are only as good as the rows underneath them. A transaction lost at a page break makes every total look plausible and still be wrong. If your bank gives you PDF statements, the PDF to Excel converter turns them into rows in your browser and checks that they add up to the statement's closing balance before you start. For a ready-made layout, see categorizing bank transactions in Excel and Google Sheets.
Related guides & tools
- PDF to Excel Converter →
Convert PDF bank statements into clean, balance-checked spreadsheets.
- Free Bank Statement Balance Checker →
Prove every extracted row adds up to the closing balance.
Related articles
- How to categorize bank transactions in Excel or Google Sheets Use a formula to suggest categories from messy bank descriptions, fix the rest by hand, and total spending by category with SUMIFS or a pivot table.
- How to convert a PDF bank statement to Excel Four ways to get a PDF bank statement into Excel, what goes wrong with each, and how to check that no transactions went missing along the way.
- How to reconcile a bank statement in Excel (with a free template) Prove your transactions add up to the statement, find the exact row when they don’t, and download a free Excel template that does the arithmetic.