Search

# Using Credit Card Numbers in Excel

Share

James asks in Custom Cell Formatting in Excel Post,

I 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:

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

Credit card Photo from Normann Copenhagen

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

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.

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.

### How to calculate WEEKNUMBER in Month / Quarter / Year with Excel?

Let’s say you have daily data and your boss wants to see the trends by week in month or week in quarter? How do you calculate the week number in a month or quarter? In this article, let me explain the logic and formulas we can use Excel for this.

## Related Tips

Excel Howtos

### How to calculate WEEKNUMBER in Month / Quarter / Year with Excel?

Charts and Graphs

Excel Howtos

Learn Excel

Excel Howtos

Learn Excel

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

### Get FREE Excel & Power-BI Newsletter

One email per week with Excel and Power BI goodness. Join 100,000+ others and get it free.Â