Case 3: bank reconciliation with VBA

Every line on the bank statement needs an entry in the books, and every bank entry in the books should turn up on a statement sooner or later. A macro ticks off both directions, flags what does not match and reports the open items with a total.

In short: Set hit = range.Find(What:=reference, LookAt:=xlWhole) looks for the reference in the other list. If hit Is Nothing, the entry is missing; otherwise compare the amount with hit.Offset(0, 2).Value. For the other direction, WorksheetFunction.CountIf(…) = 0 is enough.

The situation

Early April. The March bank statement is a list: date, reference from the payment details, payer or payee and amount, receipts positive, payments negative. The second sheet holds the entries accounting posted to the bank account in March, with document number and amount. Both lists need to be reconciled before the month is closed.

The terms

TermMeaning
ReconciliationMatching every bank movement to its entry in the books, and the other way round.
ReferenceThe invoice or document number from the payment details, here INV-… for customer invoices and BILL-… for supplier bills.
DifferenceThe document is found but the amount differs, for example because of an early payment discount, a part payment or a typo.
Open itemPresent on one side but not the other, such as bank fees with no entry or a payment still in transit.

Task 1: bank statement against the ledger

Task The Bank sheet holds the March bank statement, the Ledger sheet the entries on the bank account in the books. They are linked by the reference (Bank, column B) and the document number (Ledger, column B). Write a macro Reconcile that looks up every statement line in the ledger (Find with LookAt:=xlWhole) and writes in column E of the Bank sheet: "matched" if the document is found and the amount agrees to the cent, "difference" if the document is there but the amount is different, and "open" if there is no document. "difference" and "open" get a yellow fill (vbYellow).

Bank

ABCDE
1DateReferencePayer/payeeAmountStatus
23 Mar 2026INV-2026-112Becker Plumbing Inc5,355.00
35 Mar 2026INV-2026-109Shaw & Partners2,142.00
410 Mar 2026BILL-4471Holt Steel Supply-7,437.50
512 Mar 2026INV-2026-115Bennett Motors8,330.00
616 Mar 2026FEE 03/2026Account fee-38.50
720 Mar 2026INV-2026-117Wagner Electric1,190.00

Ledger

ABCDE
1DateDoc noPartyAmountStatus
22 Mar 2026INV-2026-109Shaw & Partners2,142.00
33 Mar 2026INV-2026-112Becker Plumbing Inc5,355.00
49 Mar 2026BILL-4471Holt Steel Supply-7,437.50
511 Mar 2026INV-2026-115Bennett Motors8,530.00
618 Mar 2026INV-2026-117Wagner Electric1,190.00
725 Mar 2026INV-2026-119Hoffman Construction3,570.00

You know Find from the lesson on Find. What matters is the order of the tests: first ask whether anything was found at all, and only then use the hit.

Set hit = ledger.Range("B2:B" & lLast).Find(What:=bank.Cells(r, "B").Value, LookAt:=xlWhole)
If hit Is Nothing Then
    ' open
ElseIf Round(hit.Offset(0, 2).Value - bank.Cells(r, "D").Value, 2) = 0 Then
    ' matched
Else
    ' difference
End If

In March four lines match exactly. Bennett Motors paid 8,330.00 instead of 8,530.00, which is a difference. The account fee of 38.50 has no entry; it is open and needs to be posted.

Task 2: the other direction, with a total

A reconciliation that only searches from the statement misses entries in the books that have no bank movement yet. So the second macro runs over the ledger and asks only: is this document number on the statement? CountIf from the lesson on WorksheetFunction is all it takes.

Task Now the other direction: which ledger entries have not gone through the bank yet? Write a macro OpenItems that counts, for every row on Ledger, how often its document number appears in the reference column of Bank (WorksheetFunction.CountIf). If it does not appear, the macro writes "open" in column E of Ledger with a yellow fill (vbYellow) and keeps a count and a running total of the amounts; otherwise it writes "matched". At the end it reports "Open items: ", the count, ", total " and the amount using Format(…, "#,##0.00"), for example "Open items: 2, total 1,250.00".

Bank

ABCDE
1DateReferencePayer/payeeAmountStatus
23 Mar 2026INV-2026-112Becker Plumbing Inc5,355.00
35 Mar 2026INV-2026-109Shaw & Partners2,142.00
410 Mar 2026BILL-4471Holt Steel Supply-7,437.50
512 Mar 2026INV-2026-115Bennett Motors8,330.00
616 Mar 2026FEE 03/2026Account fee-38.50
720 Mar 2026INV-2026-117Wagner Electric1,190.00

Ledger

ABCDE
1DateDoc noPartyAmountStatus
22 Mar 2026INV-2026-109Shaw & Partners2,142.00
33 Mar 2026INV-2026-112Becker Plumbing Inc5,355.00
49 Mar 2026BILL-4471Holt Steel Supply-7,437.50
511 Mar 2026INV-2026-115Bennett Motors8,530.00
618 Mar 2026INV-2026-117Wagner Electric1,190.00
725 Mar 2026INV-2026-119Hoffman Construction3,570.00

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

In March the invoice to Hoffman Construction for 3,570.00 is recorded as paid, but nothing has arrived on the statement. Whether the money is still in transit or the entry is wrong is for accounting to clear up; the macro makes sure it gets noticed.

Common mistakes

Using the hit without checking for Nothing

If the reference is missing, Find returns Nothing, and hit.Offset stops. The exercise shows "Run-time error '91': Object variable or With block variable not set" with the hint "The variable is Nothing. Find returns Nothing when it finds no match, so check first with If Not found Is Nothing Then."

Both tests in one condition with Or

If hit Is Nothing Or hit.Offset(0, 2).Value <> … looks right but stops with the same run-time error 91. VBA always evaluates both sides of Or and And, even when the first one already decides the result. That is why the Nothing test needs its own If or ElseIf.

Leaving out LookAt:=xlWhole

Without it, Find uses whatever setting was used last. If that is xlPart, it also finds the reference inside a longer text, such as "INV-2026-11" in "INV-2026-115". The practice data does not show it, real invoice numbers will.

In real Excel

  • Always state LookAt explicitly. According to the Microsoft documentation, Excel keeps the settings for LookIn, LookAt, SearchOrder and MatchByte from one call to the next, and they are tied to the settings in the Find dialog box.
  • Real statements rarely have the reference neatly in a column of its own, but somewhere in the payment details. Then you pull it out first with InStr and Mid, or search with LookAt:=xlPart and check the amount all the more strictly.
  • The same reconciliation with formulas is in the Excel bank reconciliation case.

Check your result

  • Task 1: column E on Bank reads, from the top: matched, matched, matched, difference, open, matched. The two yellow cells are E5 and E6.
  • Task 2: only INV-2026-119 is open, and the message reads "Open items: 1, total 3,570.00".

Next: case 4, aged receivables

Put receivables into buckets by days past due, build the aging summary and draw up a reminder list.

Go to case 4

Back to case 2 or the course overview.

Write to us

Choose language

Select your preferred language