是否有现成的excel表格来验证IBAN?我将输入IBAN,它将显示有效或无效。
我已经搜索了许多插件,找到了this one
但我不知道怎么打开它。有人能帮上忙吗?
发布于 2011-12-05 02:33:32
这很简单,只需使用以下函数即可。
'' Validate IBAN
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使用方法:
Copy the code.
In Excel press Alt + F11 to enter the VBE.
Press Ctrl + R to show the Project Explorer.
Insert -> Module.
Paste code.
Save and Exit VBE.运行函数:
现在,您在Excel中有了一个用户定义函数,就像内置的SUM、AVG函数一样。假设您想要在单元格A1中验证=VALIDATEIBAN(A1).,只需在任何单元格IBAN中写入,它将返回TRUE或FALSE。
此外,它将适用于以下两种情况:
ES65 0800 0000 1920 0014 5399和
ES6508000000192000145399但不是:
ES65-0800-0000-1920-0014-5399发布于 2013-07-02 00:56:56
这样,格式化问题解决了,并执行了"97检查“:
Public Function VALIDATEIBAN(ByVal IBAN As String) As String
' Created by : Koen Rijnsent (www.castoro.nl)
' Inspired by : Chris Fannin (AbbydonKrafts)
' Inspired by : bonsvr (http://stackoverflow.com/users/872583/bonsvr)
On Error GoTo CatchError
Dim objRegExp As Object
Dim IBANformat As Boolean
Dim IBANNR As String
Dim ReplaceChr As String
Dim ReplaceBy As String
'Check format
IBAN = UCase(IBAN)
Set objRegExp = CreateObject("vbscript.regexp")
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}"
IBANformat = objRegExp.Test(IBAN)
'Validity of country code will not be checked!
If IBANformat = False Then
VALIDATEIBAN = "FORMAT NOT RECOGNIZED"
Else
'Flip first 4 characters to the back
IBANNR = Right(IBAN, Len(IBAN) - 4) & Left(IBAN, 4)
'Replace letters by the right numbers
For Nr = 10 To 35
ReplaceChr = Chr(Nr + 55)
ReplaceBy = Trim(Str(Nr))
IBANNR = Replace(IBANNR, ReplaceChr, ReplaceBy)
Next Nr
'Loop through the IBAN, as it is too long to calculate at one go
CurrPart = ""
Answer = ""
For CurrDigit = 1 To Len(IBANNR)
CurrPart = CurrPart & Mid$(IBANNR, CurrDigit, 1)
CurrNumber = CLng(CurrPart)
'If the number can be divided
If 97 <= CurrNumber Then
LeftOver = CurrNumber Mod 97
WorkValue = (CurrNumber - LeftOver) / 97
Answer = Answer & CStr(WorkValue)
CurrPart = CStr(LeftOver)
Else
'If no division occurred, add a trailing zero
If Len(Answer) > 0 Then
Answer = Answer & "0"
'Exception for the last number
If CurrDigit = Len(IBANNR) Then
LeftOver = CurrNumber Mod 97
Else
End If
Else
End If
End If
Next
If LeftOver = 1 Then
VALIDATEIBAN = "IBAN OK"
Else
VALIDATEIBAN = "97 CHECK FAILED"
End If
End If
Exit Function
CatchError:
VALIDATEIBAN = "ERROR: " & Err.Description
MsgBox "Module: " & MODULE_NAME & " - VALIDATEIBAN function" & vbCrLf & vbCrLf _
& "Error#: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Function发布于 2016-04-27 21:45:28
Option Compare Database
Option Explicit
' http://en.wikipedia.org/wiki/International_Bank_Account_Number
Private Const IbanCountryLengths As String = "AL28AD24AT20AZ28BH22BE16BA20BR29BG22CR21HR21CY28CZ24DK18DO28EE20FO18" & _
"FI18FR27GE22DE22GI23GR27GL18GT28HU28IS26IE22IL23IT27KZ20KW30LV21LB28" & _
"LI21LT20LU20MK19MT31MR27MU30MC27MD24ME22NL18NO15PK24PS29PL28PT25RO24" & _
"SM27SA24RS22SK24SI19ES24SE24CH21TN24TR26AE23GB22VG24QA29"
Private Function ValidateIbanCountryLength(CountryCode As String, IbanLength As Integer) As Boolean
Dim i As Integer
For i = 0 To Len(IbanCountryLengths) / 4 - 1
If Mid(IbanCountryLengths, i * 4 + 1, 2) = CountryCode And _
CInt(Mid(IbanCountryLengths, i * 4 + 3, 2)) = IbanLength Then
ValidateIbanCountryLength = True
Exit Function
End If
Next i
ValidateIbanCountryLength = False
End Function
Private Function Mod97(Num As String) As Integer
Dim lngTemp As Long
Dim strTemp As String
Do While Val(Num) >= 97
If Len(Num) > 5 Then
strTemp = Left(Num, 5)
Num = Right(Num, Len(Num) - 5)
Else
strTemp = Num
Num = ""
End If
lngTemp = CLng(strTemp)
lngTemp = lngTemp Mod 97
strTemp = CStr(lngTemp)
Num = strTemp & Num
Loop
Mod97 = CInt(Num)
End Function
Public Function ValidateIban(IBAN As String) As Boolean
Dim strIban As String
Dim i As Integer
strIban = UCase(IBAN)
' Remove spaces
strIban = Replace(strIban, " ", "")
' Check if IBAN contains only uppercase characters and numbers
For i = 1 To Len(strIban)
If Not ((Asc(Mid(strIban, i, 1)) <= Asc("9") And Asc(Mid(strIban, i, 1)) >= Asc("0")) Or _
(Asc(Mid(strIban, i, 1)) <= Asc("Z") And Asc(Mid(strIban, i, 1)) >= Asc("A"))) Then
ValidateIban = False
Exit Function
End If
Next i
' Check if length of IBAN equals expected length for country
If Not ValidateIbanCountryLength(Left(strIban, 2), Len(strIban)) Then
ValidateIban = False
Exit Function
End If
' Rearrange
strIban = Right(strIban, Len(strIban) - 4) & Left(strIban, 4)
' Replace characters
For i = 0 To 25
strIban = Replace(strIban, Chr(i + Asc("A")), i + 10)
Next i
' Check remainder
ValidateIban = Mod97(strIban) = 1
End Function来源:http://www.aswinvanwoudenberg.com/2013/07/18/vba-iban-validator/
https://stackoverflow.com/questions/8377306
复制相似问题