Skip to main content
Back to Articles

Auto-Categorize Bank Transactions in Excel With a Rules Table

Build an Excel rules table that categorizes bank transactions by keyword, direction, amount and account, then test coverage and overlaps before reporting.

Excel-style table matching bank transaction descriptions and amounts to software, revenue, office, food and housing categories.

Save hours every week

Turn your bank statements (PDF) into Excel, CSV or OFX, without manual retyping.

Try it now

To auto-categorize bank transactions in Excel, keep the rules in their own table, with a keyword, a match type, a direction (money in or out), an optional amount range and an optional account for each rule. One formula then tests every rule against each row, returns the first match by priority and counts the matches, so rows with zero or several matches go to review instead of receiving a silent guess.

A plain keyword list cannot tell a $36 Amazon purchase from a $649 one, or a purchase from the refund that reverses it. The conditions below can. If the statement is still a PDF, convert the bank statement PDF to an Excel table first, or run it through a bank statement converter that keeps dates, descriptions and amounts in separate columns, then check the rows against the original pages before you write any rule.

Freelancer reviewing auto-categorized bank transactions in an Excel spreadsheet

What a rules table adds to a keyword lookup

A keyword lookup maps a fragment of the description to a category. A rules table adds conditions to that match: whether the text must be contained, start the description or equal it, whether the amount is money in or money out, whether it falls inside a range, and which account it came from. Each rule has an ID, so you can count how often it fires and spot rules that never win.

NeedKeyword lookupRules table
”ADOBE” in the description means SoftwareYesYes
A refund from the same merchant is not an expenseNoYes (Direction)
Small and large purchases from one merchant go to different categoriesNoYes (Min and Max)
A fee rule applies to one account onlyNoYes (Account)
See which rule assigned each categoryNoYes (RuleID)
Find rules that never fireNoYes (Hits column)

If you only need the basic keyword formula, the guide to categorizing bank transactions automatically covers INDEX-MATCH, exact-match VLOOKUP and the categories BankStatementLab can suggest. To total reviewed categories by month, use the PivotTable summary workflow. This article stays on the step between the two: writing and testing the rules.

Step 1: Prepare a Transactions table the rules can read

Rules are only as reliable as the columns they test. Before writing any, give each row one signed amount, an account and a cleaned description.

  1. Select the rows, press Ctrl + T and name the table Transactions under Table Design. New rows pasted under the table inherit its formulas.
  2. Keep Date, Description, Amount and Account. Amount is negative for money out and positive for money in.
  3. If the statement prints separate debit and credit columns, add Amount as =N([@Credit])-N([@Debit]), which treats a blank cell as zero.
  4. Add CleanDesc with =UPPER(TRIM(CLEAN([@Description]))). It removes non-printing characters and repeated spaces and puts the text in capitals, so every keyword in the Rules table should be typed in capitals too.

Convert text amounts to numbers before going further: a rule that compares "-54.99" stored as text with a number will not behave as expected.

Step 2: Build the Rules table

On a separate sheet, create a table named Rules with these columns, then sort it by Priority, lowest first. Excel does not reorder the table for you, and the formula reads the rows from top to bottom.

ColumnWhat it holdsBlank means
RuleIDA short, stable label such as R03Not allowed
Priority10, 20, 30… so you can insert rules laterNot allowed
MatchTypeContains, Starts with or ExactNot allowed
KeywordText in capitals, tested against CleanDescRule ignored
DirectionOut, In or AnyNot allowed
MinSmallest absolute amount the rule acceptsNo lower limit
MaxLargest absolute amount the rule acceptsNo upper limit
AccountThe account name as it appears in TransactionsAny account
CategoryThe label the rule assignsNot allowed

Use Exact for fixed descriptions such as a monthly service fee, Starts with for merchants whose descriptor begins the same way every time, and Contains for the rest. Min and Max test the absolute amount, so a $649 purchase and a $649 refund both pass a “Min 100” condition; Direction is what separates them.

Step 3: Write the matching formula

The formula below needs XLOOKUP and LET, which are available in Excel for Microsoft 365, Excel for the web, Excel 2021 and Excel 2024; Microsoft’s XLOOKUP reference notes that the function is not available in Excel 2016 and 2019. Add a RuleID column to Transactions and enter:

=LET(
  d, [@CleanDesc], a, [@Amount], acct, [@Account],
  kw, Rules[Keyword], mt, Rules[MatchType], dir, Rules[Direction],
  hitText, IF(mt="Exact", kw=d, IF(mt="Starts with", LEFT(d, LEN(kw))=kw, ISNUMBER(SEARCH(kw, d)))),
  hitDir, (dir="Any") + (dir="Out")*(a<0) + (dir="In")*(a>0),
  hitMin, (Rules[Min]="") + (ABS(a)>=Rules[Min]),
  hitMax, (Rules[Max]="") + (ABS(a)<=Rules[Max]),
  hitAcct, (Rules[Account]="") + (Rules[Account]=acct),
  ok, (kw<>"") * hitText * (hitDir>0) * (hitMin>0) * (hitMax>0) * (hitAcct>0),
  IF(SUM(ok)=0, "NONE", XLOOKUP(1, ok, Rules[RuleID]))
)

Then add a Matches column with the same formula, replacing its last line with SUM(ok). Finally, add Category:

=IF([@Matches]<>1, "Needs review", XLOOKUP([@RuleID], Rules[RuleID], Rules[Category]))

How the formula reads each rule:

  • hitText applies the rule’s match type. SEARCH is not case-sensitive and treats * and ? as wildcards, so put ~ before a literal asterisk or question mark, as Microsoft’s SEARCH documentation explains.
  • hitDir, hitMin, hitMax and hitAcct each pass when the condition is met or the rule leaves it blank.
  • ok is 1 only for rules whose conditions all pass. kw<>"" excludes rules without a keyword, which SEARCH would otherwise match to every description.
  • XLOOKUP(1, ok, …) returns the first passing rule, searching from the top of the table, which is why the Priority sort matters.

The Category formula assigns a label only when exactly one rule matches. If you prefer to let Priority settle overlaps, change <>1 to =0, but keep the Matches column so the overlaps stay visible. Record your own decisions in a separate ManualCategory column rather than overwriting the formula, as the PivotTable workflow does with its FinalCategory column.

Formulas use English function names and comma separators; a localized Excel may need translated names and semicolons. In Excel 2016 or 2019, use the INDEX-MATCH version in the automatic categorization guide and add each extra condition as another multiplied test inside MATCH.

Worked example: eight transactions, eight rules

Sample data: an invented checking account named Checking, March 2026, opening balance $4,000.00.

Rules (sorted by Priority):

RuleIDPriorityMatchTypeKeywordDirectionMinMaxAccountCategory
R0110ContainsUBER EATSOutMeals - check purpose
R0220ContainsUBEROutTravel
R0330Starts withADOBEOutSoftware
R0440ContainsSTRIPE PAYOUTInSales receipts
R0550ContainsTRANSFERAnyTransfer - exclude
R0660ContainsAMAZONOut100Office supplies
R0770ContainsAMAZONOut100.01Equipment - confirm asset
R0880ExactMONTHLY SERVICE FEEOutCheckingBank fees

Transactions after the formulas:

DateCleanDescAmountRuleIDMatchesCategory
03/02/2026ADOBE *CREATIVE CLD-54.99R031Software
03/03/2026UBER EATS 8842-23.40R012Needs review
03/05/2026STRIPE PAYOUT 3/041,250.00R041Sales receipts
03/06/2026ONLINE TRANSFER TO SAV XXXX1234-500.00R051Transfer - exclude
03/09/2026AMAZON MKTPL*2X4-36.17R061Office supplies
03/14/2026AMAZON MKTPL*9K1-649.00R071Equipment - confirm asset
03/18/2026AMAZON REFUND MKTPL*2X436.17NONE0Needs review
03/31/2026MONTHLY SERVICE FEE-12.00R081Bank fees

What the example shows:

  • The Uber Eats row matches two rules. R01 and R02 both contain “UBER”, so the row goes to review. Rename R02’s keyword to UBER TRIP and the overlap disappears.
  • The two Amazon purchases split on amount. $36.17 passes R06 (Max 100); $649.00 passes R07 (Min 100.01), a reminder to check whether the purchase is equipment.
  • The Amazon refund matches nothing. R06 and R07 accept money out only, so the $36.17 credit is not counted as an office expense. Link it to the original purchase during review.
  • The service fee rule is tied to one account. The same description on another account would stay uncategorized until you decide how to treat it.

Six of the eight rows have exactly one match, a coverage rate of 75%. The amounts add up to a net movement of $10.61, so the statement should show a closing balance of $4,010.61. Because every row carries a category, including Needs review, the category totals add up to the same $10.61; if they do not, a row is missing or a formula failed.

Step 4: Test the rules before you trust the totals

A rule that runs is not necessarily a rule that is right. Add these checks next to the tables and look at them each time you add rows or change a rule.

CheckFormulaWhat to look for
Hits per rule (in Rules)=COUNTIF(Transactions[RuleID],[@RuleID])0 means the rule never wins; a very high count on a broad keyword deserves a sample review
Coverage rate=COUNTIF(Transactions[Matches],1)/ROWS(Transactions[Matches])The share of rows with exactly one match
OverlapsFilter Matches greater than 1Rules that compete for the same descriptions
Unmatched rowsFilter RuleID = NONENew merchants, refunds and one-off payments
Control total=SUM(Transactions[Amount])Equals the closing balance minus the opening balance for that account and period

In the example, R02 shows zero hits: it matched the Uber Eats row, but R01 sits above it. With no Uber trips in March, nothing has tested R02 yet, so keep it under watch rather than assuming it works.

The control total is a check you perform against the statement, not proof that each row is correct. It cannot detect two errors that cancel out, and it only holds when the table contains one account and one complete period. Review a sample of matched rows for every new rule as well as all the unmatched ones.

Step 5: Keep the rules accurate month after month

  • Add rules from the review queue, not from memory. When a recurring descriptor lands in NONE twice, write a rule for it with the narrowest match type that works.
  • Never edit a RuleID once rows use it. Retire a rule by clearing its keyword, so past assignments stay traceable.
  • Add a Note column with who added the rule, when, and why, for example “confirmed with invoice”.
  • Re-sort by Priority after inserting a rule; the formula still reads the table from top to bottom.
  • Run the checks after each month’s rows are pasted in, then refresh any PivotTable that reads the Category column.

Transfers between your own accounts, card repayments, loan movements and owner contributions deserve their own categories so they never inflate income or expenses. The rules only suggest categories: the tax treatment of a payment still depends on its business purpose and your supporting records.

To check that each categorized movement also appears in your books, BankStatementLab’s bank reconciliation report compares processed statements with a ledger export, proposes pairs for your approval and exports Excel, CSV or PDF. Approving a match does not approve the category.

Excel pivot table and bar chart showing business expenses broken down by category

Getting the rows into Excel from a PDF statement

The rules table assumes clean rows. When a bank only gives you PDF statements, copying them into Excel tends to split descriptions, shift columns or lose minus signs, and each of those breaks a rule. BankStatementLab extracts the transaction rows into Excel, CSV or OFX with dates, descriptions and amounts in separate columns. Check every table against the original pages before applying your rules.

On the Pro plan ($29 a month for 400 credits, £24 in the UK) and the Business plan, the extraction also suggests a category when the statement prints none. You can keep that column as a starting point and let your Rules table override it for the merchants you know. New accounts include 5 credits (1 credit = 1 page), enough to test a short statement, and you can preview the first two pages of a file without an account.

Have statements in PDF? Extract the rows, check them against the statement, then paste them under your Transactions table. Create an account →

Frequently Asked Questions

Can Excel categorize bank transactions automatically without add-ins?

Yes. Keep your rules in an Excel table with a keyword, match type, direction, optional amount range and optional account, then use one formula to return the first matching rule and a second to count matches. Rows with zero or several matches go to a Needs review label, so you check them instead of trusting a silent guess.

How do I categorize bank transactions by amount as well as description?

Add Min and Max columns to the Rules table and test the absolute amount against them in the formula. A blank Min or Max means no limit. Two rules with the same keyword can then send a $36.17 purchase to Office supplies and a $649.00 purchase from the same merchant to an equipment review.

Why does my Excel formula return the wrong category?

Usually two rules match the same description and the formula returns the one higher in the table. Count matches for every row, filter rows with more than one, and either narrow the broad keyword or move the specific rule above it. Also check that amounts are numbers, not text, and that keywords are typed in capitals.

How do I keep refunds and transfers out of expense totals?

Give each rule a Direction. Expense rules accept money out only, so a refund credit from the same merchant matches nothing and goes to review, where you link it to the original purchase. Give transfers between your own accounts a dedicated rule and category, and exclude that category from income and expense reports.

Does this rules formula work in Excel 2016 or 2019?

No. The formula uses XLOOKUP and LET, which those versions do not include. Use INDEX with MATCH instead, multiply each extra condition inside MATCH, and confirm the formula with Ctrl + Shift + Enter if your version requires array entry. The rules table, checks and review steps stay the same.

---
🎁 5 credits on signup, then 5/month
💎 1 credit = 1 page

Save hours every week

Go from PDF to an Excel file ready to use, with no manual data entry.

Try BankStatementLab