fbpx
Search
Close this search box.

Using Credit Card Numbers in Excel

Share

Facebook
Twitter
LinkedIn

James asks in Custom Cell Formatting in Excel Post,

Using Credit Card Numbers in ExcelI have a problem when formatting a cell that has 16 or more digits … We are working with Credit Card numbers and want to be able to enter them as a 16 digit number like this: 1234123412341234 but want them to look like this: 1234 1234 1234 1234

The problem we’re having is that the last digit always turns into a 0 (zero) and the number ends up looking like this: 1234 1234 1234 1230 The custom format type we created is: 0000 0000 0000 0000 but we’ve also tried: #### #### #### #### with the same results.
This only happens when using 16 or more digits. If we use 15 or less digits, the Custom format works fine. Unfortunately, credit cards have 16 digits so we’re stuck with the problem.
We’ve tried this on Excel 2007 with service pack 1 and on Excel 2000 with service pack 3 with the same results. The Operating Systems we’ve tried it on are Windows XP with Service Pack 3 (and all other Microsoft Updates installed) and on Windows 2000 with Service Pack 4.

Well, this is because Excel stores numbers with precision of 15 digits. So anything more and it is automatically converted in to engineering format.

Here is a simple workaround if you need to store and work with credit card numbers in excel:

Using Custom Formats in Excel to Store Credit Card NumbersChange the cell format to TEXT from general or number. Thus excel treats numbers as text and you can escape the truncation.

But what if you need to format the credit card numbers in a special way? well, we use a knife and cut the number in to 4 small parts. Not really, we use the LEFT, MID and RIGHT formulas to process the credit card number and format it the way we want.

For eg. if you want to format the credit card number 1234123412341234 like 1234 1234 1234 1234, you can use the formula

=LEFT(B3,4)&" "&MID(B3,5,4)&" "&MID(B3,9,4)&" "&RIGHT(B3,4)

and if you want to test the credit card, you know where to go. To our Excel formula E-book page.

Also: Formatting phone numbers, SSN in Excel.

Credit card Photo from Normann Copenhagen

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

4 Responses to “Using Credit Card Numbers in Excel”

  1. Jeff says:

    Parsing so that it can do 16 digits is great. Now, add in extra script to validate the digits (check that the first number is a 4 or 5 - Visa vs Mastercard, 6 for Discover). 🙂

  2. Kirby says:

    I put the validation in another box, and point it towards the cell with the card data.
    =IF(LEFT(D3,1)="4","Visa",IF(LEFT(D3,1)="5","Mastercard", IF(LEFT(D3, 1)="6", "Discover")))

  3. vijay ranwa says:

    Sir
    i want A1 cell input Pan No. so only First 5 text and mid 4 numberand last one text only enter
    otherwise envaild

Leave a Reply