Break CCard Number into sets of four

stokie21

Board Regular
Joined
Dec 31, 2008
Messages
95
Hi guys, How do i get a cell to break a card number into sets of 4?

at the moment its in one big lump!

1234567891234567

i want the satff to enter the card number as above, but i also want excel to spit it for me so it reads 1234 5678 9123 4567


Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi guys, How do i get a cell to break a card number into sets of 4?

at the moment its in one big lump!

1234567891234567

i want the satff to enter the card number as above, but i also want excel to spit it for me so it reads 1234 5678 9123 4567


Thanks

Do you want the 16 digits separated into 4 cells of 4 or all in one cell with spaces between?
 
Upvote 0
If you want the 16 digits in one cell try

Code:
=LEFT(A1,4) & " " & MID(A1,5,4) & " " & MID(A1,9,4) & " " & RIGHT(A1,4)
 
Upvote 0
Thaks for this where do i enter it?

If i put it in the FX bar it shows it in the cell


Thanks

You can't put the function in the cell that the function references. You'll need to put the function in column B or something.
 
Upvote 0
You'll need code to split the credit card number in cell.
Code:
Option Explicit
 
Private Sub Worksheet_Change(ByVal Target As Range
 
   If Target.Address <> Cells(1, 1).Address Then Exit Sub
   If Len(Target.Value) <> 16 Then Exit Sub
 
   Application.EnableEvents = False
 
   Target.Value = Format(Target.Value, "0000 0000 0000 0000")
 
   Application.EnableEvents = True
 
End Sub
 
Upvote 0
Why not just apply a custom numberformat like this :
0000-0000-0000-0000
to all the cells you want this behaviour in?
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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