# 14 digit Check Digit Calculation in Luhn algorithm

#### zhosen

##### New Member
Hi,
I am new comer here. I need a favor to make a formula in Excel to create series of number for 14 Digit Check Digit. Here is my requirements-
I have 14 Digit of data [IMEI number] and i want to make the 15th digit as check digit as per Luhn algorithm. For example-

IMEI: 35145120840121
(5x2, 4x2, 1x2, 0x2, 4x2, 1x2, 1x2) = (10, 8, 2, 0, 8, 2, 2)
(1+0+8+2+0+8+2+2) + (3+1+5+2+8+0+2 ) = 44
Luhn Digit : 6

And final digit will be: 351451208401216
So, how to make the formula in excel? Please help me to find it out. I will appreciate if anybody can help me. thanks in advance. Have a great day!

### Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Hi,
Thanks for your reply. I check the whole post but it seems that is not working for me. I need it for 14 digit. Please reply me if there is any idea. thanks!

Alt+F11
Click Insert => Module
Paste the following code:

Code:
``````Option Explicit

Function AddLuhnDigit(target As Range) As String
Dim sTmp As String
Dim i As Integer, iTmp As Integer

For i = 2 To Len(target.Text) Step 2
sTmp = sTmp & (CInt(Mid(target.Text, i, 1)) * 2)
Next i

For i = 1 To Len(sTmp)
iTmp = iTmp + CInt(Mid(sTmp, i, 1))
Next i

For i = 1 To Len(target.Text) Step 2
iTmp = iTmp + CInt(Mid(target.Text, i, 1))
Next i

AddLuhnDigit = target.Text & (10 - (iTmp Mod 10))

End Function``````

You can then use it on your sheet like any other formula, so assuming your list of numbers is in column A, then put =AddLuhnDigit(A1) in B1 and copy down.

Let me know if it works.

Thank you nuked. Your code is great. I tried it and it works but it displays 10 instead of 0 if the check digit is 0. Please update the code so as if the check digit is 0, the code to dialysis 0 not 10. Are you able to do so?

Thank you in advance and warm regards.

Hi
Try:

Rich (BB code):
`` AddLuhnDigit = target.Text & Iif((10 - (iTmp Mod 10))=10,"0",(10 - (iTmp Mod 10)))``

Last edited by a moderator:
Hi nuked,
Now it works. Thank you very much. It will help me a lot at my school excel project. Yo are a master

Regards

please help!!!! first code worked perfectly got the same issue of displaying 10 instead of 0 if the check digit is 0. I tried the code under below but receive a compile error

Replies
3
Views
229
Replies
5
Views
243
Replies
3
Views
654
Replies
0
Views
714
Replies
3
Views
265

### Forum statistics

1,203,728
Messages
6,057,004
Members
444,902
Latest member
ExerciseInFutility

### 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.

### Which adblocker are you using?

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

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