Check Digit formula

  • Thread starter Thread starter Abdul
  • Start date Start date
A

Abdul

Dear all,

I have the following serial numbers:

41078928128
41078928136
41078928144
41078928151
41078928169
41078928177
41078928185
41078928193
41078928201

The last digit is a check digit. How can I get the formula /algorithm
to get the check digit? So that if I have the serial numbers I can add
the check digit with it?

Thanks
 
hi
assuming all of your serial numbers are the same length and start in A1,
this formula will get your check digit
=right(A1,1)
but i don't understand the rest of your question.


Regards
FSt1
 
There are lots of different check bit algorithms. It look like you values
meet the Luhn algorithm. I did not check the code below that I got from
en.wikipedia.org. You can get more info from Wikpedia.

Public Function ValidateCardNumber(strCardNumber) As Boolean ' MOD 10 check
digit. "Luhn algorithm"
On Error GoTo Err

Dim intLoop As Integer, intSum As Integer
Dim bIsAlternate As Boolean, intProduct As Integer

For intLoop = Len(strCardNumber) To 1 Step -1

If bIsAlternate = False Then
intSum = intSum + CInt(Mid(strCardNumber, intLoop, 1))
bIsAlternate = True
Else

intProduct = CInt(Mid(strCardNumber, intLoop, 1)) * 2

If Len(CStr(intProduct)) = 2 Then
intSum = intSum + CInt(Mid(intProduct, 1, 1)) +
CInt(Mid(intProduct, 2, 1))
Else
intSum = intSum + CInt(intProduct)
End If

bIsAlternate = False

End If

Next intLoop

If intSum Mod 10 = 0 Then
ValidateCardNumber = True
Else
ValidateCardNumber = False
End If

Exit Function

Err:
MsgBox "Error in ValidateCardNumber()" & vbCrLf & Err.Number &
Err.Description
End Function
 
I think he wants to know how to calculate the 11th digit starting with 10
digit data.
 
Thanks Mike and all other posters.

Great.
The initial testing shows i have got what I am looking for.

Thanks again
 
However, for Excel:
=MOD(789-1,9)+1
=6

I believe, for Excel's MOD function, you need to use the following instead
of the above?

=MOD(MOD(B1-1,9)+1,9)

Without the second MOD function, numbers like 0, 891, 333, etc. (that is,
numbers whose digits total 9) will return 9 instead of what I think should
be 0. If you do this in VBA, then the second MOD function call should not be
necessary.

Rick
 
If we wish to get rid of the IF statement, one idea...

Function GenerateCheckDigit(n) As Long
Dim Fg As Boolean 'flag
Dim P As Long
Dim T As Long

'// Odd positions values are doubled
Fg = Len(n) Mod 2 = 1 'Odd?
For P = 1 To Len(n)
T = T + (((1 - Fg) * (Mid(n, P, 1)) - 1) Mod 9) + 1
Fg = Not Fg
Next P
GenerateCheckDigit = (10 - (T Mod 10)) Mod 10
End Function

--
Dana DeLouis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top