I am writing a Macro to validate LEI codes.
LEI Code is:
Example: F50EOCWSQFAUVO9Q8Z97
Validation
I have written the below:
Sub Test()
Dim LEI_String As String
LEI_String = Range("B1")
LEI_String = Replace(LEI_String, "A", "10")
LEI_String = Replace(LEI_String, "B", "11")
LEI_String = Replace(LEI_String, "C", "12")
LEI_String = Replace(LEI_String, "D", "13")
LEI_String = Replace(LEI_String, "E", "14")
LEI_String = Replace(LEI_String, "F", "15")
LEI_String = Replace(LEI_String, "G", "16")
LEI_String = Replace(LEI_String, "H", "17")
LEI_String = Replace(LEI_String, "I", "18")
LEI_String = Replace(LEI_String, "J", "19")
LEI_String = Replace(LEI_String, "K", "20")
LEI_String = Replace(LEI_String, "L", "21")
LEI_String = Replace(LEI_String, "M", "22")
LEI_String = Replace(LEI_String, "N", "23")
LEI_String = Replace(LEI_String, "O", "24")
LEI_String = Replace(LEI_String, "P", "25")
LEI_String = Replace(LEI_String, "Q", "26")
LEI_String = Replace(LEI_String, "R", "27")
LEI_String = Replace(LEI_String, "S", "28")
LEI_String = Replace(LEI_String, "T", "29")
LEI_String = Replace(LEI_String, "U", "30")
LEI_String = Replace(LEI_String, "V", "31")
LEI_String = Replace(LEI_String, "W", "32")
LEI_String = Replace(LEI_String, "X", "33")
LEI_String = Replace(LEI_String, "Y", "34")
LEI_String = Replace(LEI_String, "Z", "35")
MsgBox Len(LEI_String)
Range("B2").Value = CCur(LEI_String) Mod 97
MsgBox CCur(LEI_String) Mod 97
End Sub
And am of course getting run-time error 6 overflow errors as the integer I am working with is 35 digits long.
Is there a way of working around this?
Numbers 1-4 always show the ID of the LOU which has issued the LEI. Numbers 5-6 have always a value of 0. Numbers/Letters 7-18 are unique to each entity. Numbers 19-20 are for verification purposes.
What Is An LEI Search? LEI number search will reveal the information contained within a Legal Entity Identifier. It can be used to check the validity of an LEI number or ensure that any information held on an entity is up to date.
The LEI is an exclusive identifier, as each legal person is only issued a single LEI number. The LEI number does not replace the national registry code of a company.
The Legal Entity Identifier (LEI) code is conceived as a key measure to improve the quality and accuracy of financial data systems for better risk management post the Global Financial Crisis. LEI is a 20-digit unique code to identify parties to financial transactions worldwide. 2.
The LEI number is too big to fit in a Decimal type. To get the modulo, you'll have to compute the modulo on each digit once converted to base 10:
Private Sub Test()
Debug.Print IsValidLEI("F50EOCWSQFAUVO9Q8Z97") ' >> True '
Debug.Print IsValidLEI("T50EOCWSQFAUVO9Q8Z97") ' >> False '
End Sub
Public Function IsValidLEI(lei As String) As Boolean
Dim i As Long, c As Long, m As Long
For i = 1 To Len(lei) ' each character '
c = AscW(Mid(lei, i, 1)) ' get the character code (see ASCII table) '
Select Case c
Case 48 To 57 ' 0-9 -> 0-9 '
m = (m * 10 + c - 48) Mod 97 ' x10 to shift 1 digit, -48 to convert to base10 '
Case 65 To 90 ' A-Z -> 10-35 '
m = (m * 100 + c - 55) Mod 97 ' x100 to shift 2 digits, -55 to convert to base10 '
Case Else
Err.Raise 5, , "Unexpected character at " & i
End Select
Next
IsValidLEI = m = 1
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With