IBAN validation on sheet

dolyschaf

New Member
Joined
Dec 6, 2006
Messages
26
I have been trying to emulate the Validating IBAN number using mod 97 directly on a worksheet here: Wikipedia - Validating an IBAN using mod97

All is fine until I need to "Compute remainder" i.e. change to 3214282912345698765432161182 to a number and use with MOD.

How do I get a text string that long to appear as a number in the cell or am I looking at this all the wrong way? Is this at all possible without VBA ?

Any help appreciated!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
From that Wikipedia page: "Any programming language or software package that is used to compute D mod 97 directly must have the ability to handle integers of more than 30 digits." Sadly, Excel does not. A Long integer in Excel tops out at 1,048,576.

So we are left with the piece-wise calculation suggested on the same page. That is doable, though without VBA it will be tremendously cumbersome.

Can you go the VBA route? If so, it's a reasonably straightforward program, which I can help with.
 
Upvote 0
And here is that program (thought it might be fun to write, and it was):

Code:
Public Function BigMod(ByVal strNumber As String) As Long

    'This function accepts as large integer as a string, and calculates
    'the mod according to the given base.  It then returns the remainder.
    'Errors result in a return value of -1
    
    
    'Declarations
    Dim strSub As String
    
    Dim i As Long
    Dim lngCount As Long
    Dim lngLoopCount As Long
    Dim lngSubMod As Long
    Dim lngModulo As Long
    
    Dim boolError As Boolean
    
    'Initialization
    lngCount = Len(strNumber)
    lngModulo = 97
    boolError = False
    
    'Checking for illegal characters in string
    For i = 1 To lngCount
        
        'Examine each character
        strSub = Mid(strNumber, i, 1)
        
        'If it's not a digit, set to error and exit loop
        If Not strSub Like "#" Then
            boolError = True
            Exit For
        End If
        
    Next i
    
    'If there was an error value, return -1 and exit the function
    If boolError Then
        BigMod = -1
        Exit Function
    End If
    
    'Now, check to see if we even need this algorithm.  We'll say
    'if it's nine digits or less, we don't need to bother
    If lngCount <= 9 Then
        BigMod = CLng(strNumber) Mod lngModulo
    Else
    
        'Otherwise, let's see how many times we need to loop through this.
        lngLoopCount = Application.WorksheetFunction.Ceiling((lngCount - 9) / 7, 1) + 1
        
        'Do the first iteration of the loop
        strSub = Left(strNumber, 9)
        lngSubMod = CLng(strSub) Mod lngModulo
        
        For i = 2 To lngLoopCount
        
            'Take the ith 7 characters
            strSub = Mid(strNumber, 3 + (i - 1) * 7, 7)
        
            'Append the previous to the beginning
            strSub = Format(lngSubMod, "00") & strSub
        
            'Take the modulo of the result
            lngSubMod = CLng(strSub) Mod lngModulo

        Next i
        
        'Once we've iterated all the way through, the last result
        'is our answer
        BigMod = lngSubMod
        
    End If

End Function

I don't know this algorithm well enough to know if it's extensible to other modulo values than 97, but now I want to find out.
 
Upvote 0

Forum statistics

Threads
1,223,158
Messages
6,170,423
Members
452,325
Latest member
BlahQz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top