Excel Formula for Validating IBAN Codes with Country-Specific Lengths

📅 Aug 09, 2026 📝 Sarah Miller

Managing global transactions often leads to frustrating payment failures due to mistyped IBANs. While standard funding sources like international grants and wire systems facilitate these transfers, seamless processing relies heavily on upfront data integrity. Implementing a robust Excel validation formula grants your finance team immediate operational efficiency by eliminating manual verification errors.

As a key stipulation, remember that IBAN structures vary by territory; for example, Germany (DE) requires exactly 22 characters, whereas the United Kingdom (GB) requires 22. Below, we provide the step-by-step logical formulas and lookup tables necessary to systematically audit your financial data.

Excel Formula for Validating IBAN Codes with Country-Specific Lengths

Validating an International Bank Account Number (IBAN) in Excel is a critical task for finance professionals, accountants, and system administrators. An invalid IBAN can lead to failed transactions, processing delays, and administrative penalties. Because IBANs vary in length from country to country (ranging from 15 to 34 characters) and must satisfy a strict mathematical checksum (the MOD-97 rule), manual verification is highly prone to error.

In this comprehensive guide, we will build a robust, step-by-step Excel solution to validate any IBAN. We will cover how to clean input data, cross-reference country-specific lengths, check structural formatting, and execute the complex MOD-97 calculation directly inside Excel without relying on external APIs.

Understanding the Structure of an IBAN

Before jumping into Excel formulas, it is important to understand what makes an IBAN valid. An IBAN is an alphanumeric string composed of three main parts:

  • Country Code (2 Letters): Identifies the nation where the account is held (e.g., "DE" for Germany, "GB" for the United Kingdom).
  • Check Digits (2 Numbers): Calculated using the MOD-97 algorithm to provide a basic integrity check of the entire number.
  • Basic Bank Account Number (BBAN): Up to 30 alphanumeric characters. The length and format of the BBAN are defined individually by each country's banking authority.

The Three Pillars of IBAN Validation

To fully validate an IBAN in Excel, our system must perform three distinct checks:

  1. Data Sanitization: Strip out spaces, hyphens, and force uppercase formatting.
  2. Country-Specific Length Verification: Ensure the IBAN's length matches the exact standard established for its specific country.
  3. MOD-97 Checksum Validation: Rearrange the string, convert letters to numbers, and verify that the mathematical remainder of the massive integer divided by 97 equals 1.

Step 1: Sanitizing the Input Data

Users often input IBANs with spaces (e.g., DE89 3704 0044 0532 0130 00) or hyphens. To prevent these characters from breaking our formulas, we must clean the string first. Assuming your raw IBAN is in cell A2, use the following formula to sanitize it:

=UPPER(SUBSTITUTE(SUBSTITUTE(A2, " ", ""), "-", ""))

This formula converts all letters to uppercase and removes both spaces and hyphens, giving us a clean, continuous string of alphanumeric characters.


Step 2: Checking Country-Specific Lengths

Even if an IBAN passes a basic mathematical test, it is invalid if it does not match its home country's designated length. For example, a German IBAN (DE) must be exactly 22 characters, a French one (FR) must be 27, and a Belgian one (BE) must be 16.

To implement this in Excel, we use a reference table of ISO Country Codes and their respective IBAN lengths. Below is a lookup table of common country codes and their standard lengths:

Country Code Country Name IBAN Length
ADAndorra24
ATAustria20
BEBelgium16
CHSwitzerland21
DEGermany22
DKDenmark18
ESSpain24
FIFinland18
FRFrance27
GBUnited Kingdom22
GRGreece27
IEIreland22
ITItaly27
LULuxembourg20
NLNetherlands18
NONorway15
PLPoland28
PTPortugal25
SESweden24

If you set up this table in a separate tab named IBAN_Rules within columns A:C, you can use the following formula to verify that the length of your cleaned IBAN matches its official national standard:

=LET(
    CleanIBAN, UPPER(SUBSTITUTE(SUBSTITUTE(A2, " ", ""), "-", "")),
    CountryCode, LEFT(CleanIBAN, 2),
    ActualLength, LEN(CleanIBAN),
    ExpectedLength, XLOOKUP(CountryCode, IBAN_Rules!$A:$A, IBAN_Rules!$C:$C, 0),
    IF(ExpectedLength = 0, "Invalid Country Code", IF(ActualLength = ExpectedLength, "Length OK", "Invalid Length"))
)

This LET-driven formula isolates the country code, counts the actual characters, matches them against our reference table, and outputs a clear warning if the length or country code is incorrect.


Step 3: The MOD-97 Checksum (The Mathematical Validation)

The MOD-97 checksum (governed by ISO 7064) is the ultimate test of an IBAN's authenticity. The mathematical process requires you to:

  1. Move the first four characters of the IBAN (Country Code and Check Digits) to the end of the string.
  2. Replace each letter in the string with its corresponding two-digit numeric position in the alphabet (where A = 10, B = 11, ..., Z = 35).
  3. Divide this extremely long integer by 97. If the remainder (Modulo) is 1, the IBAN is valid.

The Excel Precision Limitation

Standard Excel math functions can only handle numbers up to 15 digits of precision. Because an expanded IBAN can easily be 30 to 70 digits long, using a standard formula like =MOD(VALUE(IBAN_Number), 97) will fail, yielding a #NUM! or incorrect rounding error.

To bypass this limitation without VBA, we can utilize Excel 365's dynamic array functions (specifically REDUCE and LAMBDA) to process the large number iteratively, digit-by-digit, applying modular arithmetic properties.

The Modern Excel 365 Checksum Formula

If you are using Microsoft 365 or Excel 2021, you can use this state-of-the-art array formula to calculate the MOD-97 checksum of the IBAN in cell A2:

=LET(
    Clean, UPPER(SUBSTITUTE(SUBSTITUTE(A2, " ", ""), "-", "")),
    Rearranged, MID(Clean, 5, LEN(Clean)) & LEFT(Clean, 4),
    ConvertChar, LAMBDA(char, LET(code, CODE(char), IF(AND(code >= 65, code <= 90), TEXT(code - 55, "0"), char))),
    NumString, REDUCE("", MID(Rearranged, SEQUENCE(LEN(Rearranged)), 1), LAMBDA(acc, val, acc & ConvertChar(val))),
    Checksum, REDUCE(0, MID(NumString, SEQUENCE(LEN(NumString)), 1), LAMBDA(rem, digit, MOD(rem * 10 + VALUE(digit), 97))),
    IF(Checksum = 1, "VALID Checksum", "INVALID Checksum")
)

How this formula works:

  • Clean: Sanitizes the input string.
  • Rearranged: Shifts the first four characters to the end.
  • ConvertChar: A helper lambda function that identifies letters (ASCII values 65–90) and converts them to their numeric values (A → 10, etc.), keeping numbers as-is.
  • NumString: Iterates through each character in the rearranged IBAN using REDUCE and joins them into a giant string of digits.
  • Checksum: Uses a digit-by-digit division algorithm: $(Remainder \times 10 + NextDigit) \pmod{97}$. This allows Excel to process an infinite number of digits without experiencing floating-point overflow.

Step 4: Creating a Master Validation Formula

To make this practical for professional dashboards, we can combine our country-specific length validation and our mathematical checksum check into a single master formula. This ensures that a passing mark satisfies both structural and mathematical requirements.

=LET(
    Clean, UPPER(SUBSTITUTE(SUBSTITUTE(A2, " ", ""), "-", "")),
    CountryCode, LEFT(Clean, 2),
    ActualLength, LEN(Clean),
    ExpectedLength, XLOOKUP(CountryCode, IBAN_Rules!$A:$A, IBAN_Rules!$C:$C, 0),
    IsLengthValid, IF(ExpectedLength = 0, FALSE, ActualLength = ExpectedLength),
    Rearranged, MID(Clean, 5, LEN(Clean)) & LEFT(Clean, 4),
    ConvertChar, LAMBDA(char, LET(code, CODE(char), IF(AND(code >= 65, code <= 90), TEXT(code - 55, "0"), char))),
    NumString, REDUCE("", MID(Rearranged, SEQUENCE(LEN(Rearranged)), 1), LAMBDA(acc, val, acc & ConvertChar(val))),
    Checksum, REDUCE(0, MID(NumString, SEQUENCE(LEN(NumString)), 1), LAMBDA(rem, digit, MOD(rem * 10 + VALUE(digit), 97))),
    IF(NOT(IsLengthValid), "INVALID (Length/Country Error)", IF(Checksum = 1, "VALID", "INVALID (Checksum Failure)"))
)

This master formula returns VALID only when the country-specific length matches and the mathematical checksum is successful. Otherwise, it points out the exact reason for the failure.


Backward Compatible Alternative: VBA Macro (For Older Excel Versions)

If your team uses older versions of Excel (such as Excel 2013, 2016, or 2019) that do not support dynamic array functions like LET, REDUCE, or XLOOKUP, you can easily implement this validation using a User-Defined Function (UDF) in VBA.

To add this macro to your workbook:

  1. Press ALT + F11 to open the VBA Editor.
  2. Click Insert > Module.
  3. Paste the following code into the code window:
Function ValidateIBAN_VBA(ByVal IBAN As String) As String
    Dim CleanIBAN As String, Rearranged As String
    Dim i As Integer, char As String, numStr As String
    Dim remainder As Integer
    
    ' Step 1: Clean input
    CleanIBAN = Replace(Replace(UCase(IBAN), " ", ""), "-", "")
    
    ' Step 2: Check standard minimum and maximum lengths
    If Len(CleanIBAN) < 15 Or Len(CleanIBAN) > 34 Then
        ValidateIBAN_VBA = "INVALID (Length Range)"
        Exit Function
    End If
    
    ' Step 3: Rearrange
    Rearranged = Mid(CleanIBAN, 5) & Left(CleanIBAN, 4)
    
    ' Step 4: Convert characters to numbers
    numStr = ""
    For i = 1 To Len(Rearranged)
        char = Mid(Rearranged, i, 1)
        If IsNumeric(char) Then
            numStr = numStr & char
        Else
            numStr = numStr & (Asc(char) - 55)
        End If
    Next i
    
    ' Step 5: Large Number Modulo 97 calculation
    remainder = 0
    For i = 1 To Len(numStr)
        remainder = (remainder * 10 + Val(Mid(numStr, i, 1))) Mod 97
    Next i
    
    ' Step 6: Return validation result
    If remainder = 1 Then
        ValidateIBAN_VBA = "VALID"
    Else
        ValidateIBAN_VBA = "INVALID (Checksum)"
    End If
End Function

Once you close the VBA window, you can use this validation function directly in your spreadsheets like any regular formula:

=ValidateIBAN_VBA(A2)

Best Practices & Operational Tips

  • Ensure Exact Rulesets: Keep your IBAN_Rules country reference table up to date. While changes to IBAN structural lengths are rare, newly participating countries are periodically added to the SWIFT registry.
  • Integrate with Data Validation: You can apply these validation rules directly to your data entry worksheets using Excel's Data Validation tool to prevent users from inputting invalid formats in the first place.
  • Color Coding: Pair your validation output column with Conditional Formatting (e.g., light green background for "VALID", light red for "INVALID") to build highly scannable, visual accounting reports.

By implementing these robust formula blocks or VBA solutions, you can guarantee data integrity, optimize your financial reporting workflows, and reduce payment transaction error rates to zero.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.