Combination

Find the customer from a bank description

Cut the invoice number out of a bank statement description with TEXTAFTER and TEXTBEFORE, then look up the customer in the receivables list with XLOOKUP.

Functions used:TEXTAFTERTEXTBEFOREXLOOKUPExcel 2024 or later (This combination needs Excel 2024 or later)

Difficulty rating 3 of 5

Worked example

Customer behind a bank receipt

Scenario

For the receivables work at Veldhuis Installatie BV you are matching bank receipts to the receivables list. Each description holds the invoice number after the label REF:. You want the customer name next to the receipt, without retyping the number, and a clear message when the invoice is not on the list.

The data

Sheet excerpt: H3 holds the formula
RowABCDEFGHI
1Invoice no.CustomerOpen amountBank descriptionSEPA OVERBOEKING REF:25-0433 BETALING DEBITEUR
225-0412Mulder Bouw BV€12,100.00€ 12.100,00
325-0415De Vries Transport€8,470.00€ 8.470,00CustomerBakker Groothandel=XLOOKUP(TEXTBEFORE(TEXTAFTER(H1, "REF:"), " ", 1, 0, 1), A2:A7, B2:B7, "Not in receivables", 0)=XLOOKUP(TEXTBEFORE(TEXTAFTER(H1; "REF:"); " "; 1; 0; 1); A2:A7; B2:B7; "Not in receivables"; 0)
425-0420Jansen Installatie€3,025.00€ 3.025,00
525-0433Bakker Groothandel€15,730.00€ 15.730,00
625-0441Smit Verhuur€6,050.00€ 6.050,00
725-0447Van Dijk Schilderwerk€1,210.00€ 1.210,00
8
Formula cell (H3)Input

Formula in H3

=XLOOKUP(TEXTBEFORE(TEXTAFTER(H1, "REF:"), " ", 1, 0, 1), A2:A7, B2:B7, "Not in receivables", 0)
=XLOOKUP(TEXTBEFORE(TEXTAFTER(H1; "REF:"); " "; 1; 0; 1); A2:A7; B2:B7; "Not in receivables"; 0)

Result: Bakker Groothandel

How the pieces fit together

The formula taken apart, from the inside out. Each part can be typed into its own cell to see what it returns.

  1. =TEXTAFTER(H1, "REF:")
    =TEXTAFTER(H1; "REF:")

    Returns everything after the label REF: in the description. The result is the text 25-0433 BETALING DEBITEUR: the invoice number is still followed by the rest of the description.

  2. =TEXTBEFORE(TEXTAFTER(H1, "REF:"), " ", 1, 0, 1)
    =TEXTBEFORE(TEXTAFTER(H1; "REF:"); " "; 1; 0; 1)

    TEXTBEFORE keeps the part before the first space, so only 25-0433 remains. The last argument, 1, lets the end of the text count as a delimiter, so an invoice number at the very end of a description is also returned.

  3. =TEXTBEFORE(TEXTAFTER(H1, "REF:"), " ", 1, 0, 1)=A2:A7
    =TEXTBEFORE(TEXTAFTER(H1; "REF:"); " "; 1; 0; 1)=A2:A7

    Compares the extracted number with the six invoice numbers in A2:A7. The result is one column: FALSE, FALSE, FALSE, TRUE, FALSE, FALSE. Only the fourth invoice, 25-0433, matches.

  4. =XLOOKUP(TEXTBEFORE(TEXTAFTER(H1, "REF:"), " ", 1, 0, 1), A2:A7, B2:B7, "Not in receivables", 0)
    =XLOOKUP(TEXTBEFORE(TEXTAFTER(H1; "REF:"); " "; 1; 0; 1); A2:A7; B2:B7; "Not in receivables"; 0)

    XLOOKUP searches 25-0433 in A2:A7, finds it in the fourth row and returns the customer from the same row of B2:B7: Bakker Groothandel. If the number is not in the list, it shows the not-found text instead of #N/A.

Step by step

  1. TEXTAFTER(H1, "REF:") cuts the description at the label and keeps what follows: 25-0433 BETALING DEBITEUR.
  2. TEXTBEFORE(..., " ", 1, 0, 1) keeps the part before the first space: 25-0433.
  3. XLOOKUP compares 25-0433 with A2:A7: 25-0412, 25-0415 and 25-0420 do not match, 25-0433 is the fourth value, so the match is in position 4.
  4. Position 4 of B2:B7 (Mulder Bouw BV, De Vries Transport, Jansen Installatie, Bakker Groothandel) is Bakker Groothandel, the result.

Why it works

The label REF: is a fixed anchor, so TEXTAFTER does not need to know where in the description the number sits or how long the text before it is. TEXTBEFORE then cuts off the tail at the next space. What remains is a clean key, and XLOOKUP does an ordinary exact lookup with it.

Watch out for

  • If the description has no REF: label, TEXTAFTER returns #N/A, and XLOOKUP passes that error on. The not-found text only appears when the label is present but the number is not in the list.
  • By default the label is matched with capitals. A bank that writes Ref: gives #N/A. Set the fourth argument of TEXTAFTER to 1 to ignore case.
  • Some banks put a character straight after the number, for example 25-0433/. The cut at the space then leaves the slash in the key and the lookup fails. Check a few descriptions of each bank before you copy the formula down.

Variations

=IFERROR(INDEX(B2:B7, MATCH(MID(H1, FIND("REF:", H1) + 4, 7), A2:A7, 0)), "Not in receivables")
=IFERROR(INDEX(B2:B7; MATCH(MID(H1; FIND("REF:"; H1) + 4; 7); A2:A7; 0)); "Not in receivables")

The older way without TEXTAFTER: FIND gives the label at position 18, so MID starts at 18 + 4 = 22 and takes 7 characters (25-0433). It only works while every invoice number has exactly 7 characters, and IFERROR also hides a missing label.

=IFERROR(INDEX(B2:B7, MATCH(TRUE, ISNUMBER(SEARCH(A2:A7, H1)), 0)), "Not in receivables")
=IFERROR(INDEX(B2:B7; MATCH(TRUE; ISNUMBER(SEARCH(A2:A7; H1)); 0)); "Not in receivables")

Works without a label: it checks which invoice number from A2:A7 occurs anywhere in the description. Handy when the number has no fixed position, but it can match a number inside a longer one.

All combinations