Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Stephanie
 
Posts: n/a
Default How do I do a MOD-10 Credit Card check in Excel?

Does anyone know how to do a MOD-10 credit card number check in Excel 2000?
Is there a way to do it using a macro and Visual Basic?
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Here is a simple function


Function ccCheck(rng) As Boolean
Dim i As Long
Dim tmp

With rng
For i = 1 To Len(.Value) - 1
tmp = tmp + Val(Mid(.Value, i, 1))
Next i
ccCheck = tmp Mod 10 = Val(Right(.Value, 1))
End With

End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Stephanie" wrote in message
...
Does anyone know how to do a MOD-10 credit card number check in Excel

2000?
Is there a way to do it using a macro and Visual Basic?



  #3   Report Post  
Dana DeLouis
 
Posts: n/a
Default

Hello. I might be wrong, but it looks like a credit card check multiplies
each digit by an alternating series of 1's or 2's. You then Sum the
individual digits. If the Total divides by 10, the number is valid. If
this is correct, here is one idea. If you wanted, you can check for leading
characters that are valid for MasterCard, Visa, etc. I used a string
variable since entering a 16 digit number would have to be done as a string.
My credit card showed "Valid" as a check.
I'm not an expert here, so hopefully some ideas here will help.

Function CC_Check(n As String) As Boolean
'// Dana DeLouis
Dim P As Long 'Pointer
Dim Tot As Long
Dim digit As Long
Dim s As Long

Select Case Len(n)
Case 13 To 16
'Valid Length
'// Make Even Length
If Len(n) Mod 2 = 1 Then n = "0" & n

For P = Len(n) To 1 Step -1
'// = = = = = = = = =
'Option #1
'// = = = = = = = = =
' Get Character
s = Mid$(n, P, 1)
' Multiply by 1 or 2
digit = s * (1 + (P Mod 2))
' Sum the individual digits (ie 12 = 1+2=3)
Tot = Tot + ((digit - 1) Mod 9) + 1

'Option #2 - Combines the 3 lines above...
'// = = = = = = = = =
' Tot = Tot + ((Mid$(n, P, 1) * (1 + (P Mod 2)) - 1) Mod 9) + 1
'// = = = = = = = = =

Next P
CC_Check = (Tot Mod 10) = 0

Case Else
'Invalid
CC_Check = "Invalid Length"
End Select

End Function


--
Dana DeLouis
Win XP & Office 2003


"Bob Phillips" wrote in message
...
Here is a simple function


Function ccCheck(rng) As Boolean
Dim i As Long
Dim tmp

With rng
For i = 1 To Len(.Value) - 1
tmp = tmp + Val(Mid(.Value, i, 1))
Next i
ccCheck = tmp Mod 10 = Val(Right(.Value, 1))
End With

End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Stephanie" wrote in message
...
Does anyone know how to do a MOD-10 credit card number check in Excel

2000?
Is there a way to do it using a macro and Visual Basic?





  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default

Hi Dana,

I am no expert either, and if I recall now (now that you have prompted me
;-)), the only mod checking I ever did multiplied each digit by a weighting
(I don't recall it being as straight-forward as 1 or 2, but my memory may be
failing).

I hope the OP knows the algorithm at the very least, my intent was to show
him how to do a mod check. I think (hope) that with that, and your helpful
advice, he should be on the road.

Regards

Bob


"Dana DeLouis" wrote in message
...
Hello. I might be wrong, but it looks like a credit card check multiplies
each digit by an alternating series of 1's or 2's. You then Sum the
individual digits. If the Total divides by 10, the number is valid. If
this is correct, here is one idea. If you wanted, you can check for

leading
characters that are valid for MasterCard, Visa, etc. I used a string
variable since entering a 16 digit number would have to be done as a

string.
My credit card showed "Valid" as a check.
I'm not an expert here, so hopefully some ideas here will help.

Function CC_Check(n As String) As Boolean
'// Dana DeLouis
Dim P As Long 'Pointer
Dim Tot As Long
Dim digit As Long
Dim s As Long

Select Case Len(n)
Case 13 To 16
'Valid Length
'// Make Even Length
If Len(n) Mod 2 = 1 Then n = "0" & n

For P = Len(n) To 1 Step -1
'// = = = = = = = = =
'Option #1
'// = = = = = = = = =
' Get Character
s = Mid$(n, P, 1)
' Multiply by 1 or 2
digit = s * (1 + (P Mod 2))
' Sum the individual digits (ie 12 = 1+2=3)
Tot = Tot + ((digit - 1) Mod 9) + 1

'Option #2 - Combines the 3 lines above...
'// = = = = = = = = =
' Tot = Tot + ((Mid$(n, P, 1) * (1 + (P Mod 2)) - 1) Mod 9) + 1
'// = = = = = = = = =

Next P
CC_Check = (Tot Mod 10) = 0

Case Else
'Invalid
CC_Check = "Invalid Length"
End Select

End Function


--
Dana DeLouis
Win XP & Office 2003


"Bob Phillips" wrote in message
...
Here is a simple function


Function ccCheck(rng) As Boolean
Dim i As Long
Dim tmp

With rng
For i = 1 To Len(.Value) - 1
tmp = tmp + Val(Mid(.Value, i, 1))
Next i
ccCheck = tmp Mod 10 = Val(Right(.Value, 1))
End With

End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Stephanie" wrote in message
...
Does anyone know how to do a MOD-10 credit card number check in Excel

2000?
Is there a way to do it using a macro and Visual Basic?







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
check box in Excel? Mike B. Excel Worksheet Functions 2 January 31st 05 02:53 PM
How do I enter a working check box option in Excel? Lisa the CPA Excel Discussion (Misc queries) 1 January 31st 05 07:07 AM
How do I add a check box to an excel spreadsheet? Alaska Massie Excel Discussion (Misc queries) 1 January 17th 05 01:19 AM
Why does spelling check close Excel when checking spanish? RCP Excel Discussion (Misc queries) 2 December 4th 04 07:37 PM


All times are GMT +1. The time now is 05:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"