Skip to content

Auto-categorize bank transactions in Google Sheets with REGEXMATCH and IFS formulas

Excel, Sheets & tax prep · · 5 min read

Bank descriptions are messy: UBER *TRIP 8XK2, Uber Eats, SHELL OIL 574412093. Google Sheets' REGEXMATCH can test a description against a whole list of merchants at once, so one formula sorts every row into a category without a nest of IF statements.

The formula

With descriptions in column B, put this in a new Category column and fill it down:

=IFS(REGEXMATCH(B2, "(?i)uber eats|doordash|grubhub"), "Meals", REGEXMATCH(B2, "(?i)uber|lyft|shell|chevron"), "Travel", REGEXMATCH(B2, "(?i)\baws\b|google|adobe|slack"), "Software", TRUE, "Uncategorized")
  • The pipe (|) means "or". Each REGEXMATCH checks one category's merchants in one go.
  • (?i) ignores case, so "Uber", "UBER" and "uber" all match without wrapping the description in UPPER.
  • IFS stops at the first match, and TRUE, "Uncategorized" at the end catches everything else.

Watch for these

  • Order matters. "Uber Eats" also contains "uber", so Meals has to come before Travel or every food delivery is filed as a ride. Put the more specific pattern first.
  • Short keywords match inside other words. "aws" matches "DRAWS" and "LAWSON". \b marks a word boundary, so \baws\b matches AWS only on its own.
  • Some characters mean something in a pattern. A dot matches any character and *, +, ( and ? have their own meanings. To match SQ *BLUE BOTTLE literally, write sq \*blue bottle.
  • REGEXMATCH is Google Sheets only. In Excel for Microsoft 365, REGEXTEST does the same job; the keyword table with XLOOKUP works in any recent Excel.

When the formula gets long

Past a few categories, one long IFS is hard to keep up to date. Move the patterns to a Rules sheet (pattern in column A, category in column B) and look them up instead:

=IFERROR(INDEX(FILTER(Rules!$B$2:$B, Rules!$A$2:$A<>"", REGEXMATCH(B2, "(?i)" & Rules!$A$2:$A)), 1), "Uncategorized")

FILTER keeps the categories whose pattern matches, and INDEX takes the first, so the order of the Rules sheet decides ties. Adding a merchant is then one new row, not an edit to a formula.

Then summarize

With every row categorized, a pivot table (Insert, then Pivot table) with Category as rows, the month as columns and the sum of Amount as values gives you spending by category per month.

Start from a statement that adds up

If your bank only gives you PDF statements, the PDF to CSV converter turns them into rows you can import into Google Sheets, and checks that they add up to the statement's closing balance first, so the totals in your pivot table are complete.

Related guides & tools

Related articles