Luhn Test (Credit and Debit Card Number Validator - Worldwide) Within Excel - Build-In Algorithm ?

puppy

New Member
Joined
May 2, 2016
Messages
3
Hi All !

For validating credit and debit card numbers, regardless of their type and country where they were issued, I am wondering if Excel Pro 2013 (windows 10) has any feature to validate the card number located in few houndreds, few thousands or few tens of thousands of cells, all in the same column? Each cell containing different card number which is going to be validated. If yes, how can I use this feature and where to access it?

Answer would be appreciated.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
are you going to use the WEB to validate the numbers or are you going to define the rules

eg UK mastercard xxxx xxxx xxxx xxxx
 
Upvote 0
Excel doesn't specifically have a tool for Luhn, but you can do the math using formulas. E.g.:


Excel 2013
ABCDEFG
1NumberKeyCheck NumReverse KeyMult 2 less 9Mod 10Result
245567375868998554556737586899855589986857376554855TRUE
Sheet1
Cell Formulas
RangeFormula
B2=LEFT(A2,15)
C2=RIGHT(A2,1)
F2=TEXT(MOD(E2,10),0)
G2=F2=C2
D2{=TEXT(SUM(MID(B2,reverse_sequence,1)*10^(reverse_sequence-1)),0)}
E2{=TEXT(SUM(IF(MID(D2,sequence,1)*multiplier>9,MID(D2,sequence,1)*multiplier-9,MID(D2,sequence,1)*multiplier)),0)}
Press CTRL+SHIFT+ENTER to enter array formulas.
Named Ranges
NameRefers ToCells
multiplier={2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}
reverse_sequence={15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}
sequence={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
 
Upvote 0
Jon: I don't have such sections of a card numbers. In B column I only have few thousands or few tens of thousands of card numbers I would like to verify whether or not number is correct. Thats all.

Macropod: I wish i knew what to do with this code :(
 
Upvote 0
Add the following function to an ordinary code module in your workbook:
Code:
Function ValidateLuhn(ByVal oCell As Range) As Boolean
Dim i As Long, j As Long, k As Long, StrTmp As String
ValidateLuhn = False
StrTmp = Replace(Replace(oCell.Value, " ", ""), "-", "")
If IsNumeric(StrTmp) Then
  Select Case Len(StrTmp)
    Case 14: If Left(StrTmp, 1) <> 3 Then Exit Function 'Diners Club
    Case 15 'Amex
      If Left(StrTmp, 1) <> 3 Then Exit Function
      StrTmp = "0" & StrTmp
    Case 16 'Visa = 4, MasterCard = 5, Discover = 6
      If (Left(StrTmp, 1) < 4) Or (Left(StrTmp, 1) > 6) Then Exit Function
    Case Else: Exit Function
  End Select
  For i = 1 To Len(StrTmp)
    j = Mid(StrTmp, i, 1) * (i Mod 2 + 1)
    k = k + Int(j / 10) + j Mod 10
  Next
  If k Mod 10 = 0 Then ValidateLuhn = True
End If
End Function
To use it, simply input the formula as:
=ValidateLuhn(A1)
in any cell, where 'A1' is the address of the cell you want to test. The function should return TRUE for valid card #s; FALSE otherwise.
 
Upvote 0
Jon: I don't have such sections of a card numbers. In B column I only have few thousands or few tens of thousands of card numbers I would like to verify whether or not number is correct. Thats all.

Macropod: I wish i knew what to do with this code :(
The numbers go in column A. The formulas in columns B:G are copied down to the end of the range (i.e. adjacent to all numbers). The final result is displayed in column G.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,614
Members
452,661
Latest member
Nonhle

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