Can someone help me create a function in Visual Basic for Applications (Excel) for verifying Belgian IBAN numbers? So I can add a list of numbers in Excel and it validates them as TRUE or FALSE.
Example of a Belgian IBAN number:
BE43 1325 3117 7701
I have tried several things before asking for help. I've tried to adjust code I found in an earlier topic on this site, which was:
Public Function VALIDATEIBAN(ByVal IBAN As string) As Boolean
On Error GoTo Catch
Dim objRegExp As Object
Dim blnIsValidIBAN As Boolean
Set objRegExp = CreateObject("vbscript.regexp")
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "^[a-zA-Z]{2}\d{2}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}|CZ\d{22}$"
blnIsValidIBAN = objRegExp.Test(IBAN)
VALIDATEIBAN = blnIsValidIBAN
Exit Function
Catch:
VALIDATEIBAN = False
MsgBox "Module: " & MODULE_NAME & " - VALIDATEIBAN function" & vbCrLf & vbCrLf _
& "Error#: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Function
I've been trying to modify by adjusting:
objRegExp.Pattern = "^[a-zA-Z]{2}\d{2}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}|CZ\d{22}$"
I started with the obvious, removing eight positions of the check like this:
objRegExp.Pattern = "^[a-zA-Z]{2}\d{2}[ ]\d{4}[ ]\d{4}[ ]\d{4}|CZ\d{22}$"
This way I can get the code in Excel to "verify" as true or false, but I think by just removing the positions from the code I also remove the code's ability to perform an actual verification on the IBAN number.