![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi all,
I have an interesting one... am looking for a way to verify a credit card number using the check digit (there's standard formula). I saw the source code on the net but its in C. Just wondering does anyone have it in vba. Thanks. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
If the code in C is short, slap it in here and maybe a kind person code convert it to VB.
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
There are loads of code examples around in any language you can think of. How about this:-
http://mskadu.freeservers.com/articl...luhncheck.html HTH, D |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
|
Hi,
for a non-VBA approach, try this cumbersome formula : assuming A1 houses your credit card number : =IF(MOD(SUM(IF((MID(TEXT(+A1,"00000000000000000000"),{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20},1)*({2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1}))<10,(MID(TEXT(+A1,"00000000000000000000"),{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20},1)*({2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1})),MID((MID(TEXT(+A1 ,"00000000000000000000"),{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20},1)*({2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1})),1,1)+MID((MID(TEX T(+A1,"00000000000000000000"),{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20},1)*({2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1;2;1})),2,1))),10)=0,"Okay","Not valid") I'm sure it could be shortened *slightly*, but it seems to work on my credit card numbers (first 15 digits). It looks at the number for validity rather than the check digit, so not exactly what you asked for, but it might help.
__________________
:: Pharma Z - Family drugstore :: |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|