Cell formatting for 16 digit numbers

mgauci

New Member
Joined
Nov 6, 2002
Messages
21
Somebody please help !
I need to find a way to format a cell so that when I type in a 16 digit credit card number the formatting will appear as the 16 digit number with a dash between every fourth digit. I can set this up by using ####-####-####-#### and although this works it changes the last value to a zero regardles of what I originally typed in. Any help would be much appreciated.
 
On 2002-11-07 23:03, Joe Was wrote:
This is event code to auto-format cell "A2" to a ####-####-####-#### formated string, after enter is pressed or a new cell is selected. JSW

Private Sub Worksheet_Change(ByVal Target As Range)
'Go's in the Sheet Module of operation.
'Will automatically convert any number in cell "A2"
'to a formated string!
Dim MyString
If [A2] <> "" Then
Range("A2").Select
Selection.NumberFormat = "@"
MyString = [A2].Value
[A2].Value = Format(MyString, "####-####-####-####")
Else
Exit Sub
End If
End Sub
Thanks Joe your macro worked, however I have another question to ask. My aim is to type a list of card numbers into a spreadsheet and then have all of them display the same formatting. How can I change the macro so that it runs for a range of cells instead of just one. (Sorry for my lack of knowledge with macros!)
Your help is greatly appreciated!!!! :)
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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