View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Custom Number Format

I am assuming you want the 16-digit "number" you enter to be changed within
the cell it was entered in. There are two possibilities to your request;
both assume the cells are formatted as Text (which, as has been pointed out,
is required so as not to lose the 16th digit)...

1) You already entered the numbers and want to change them. If this is the
case, you can select those already filled in cells and run this macro...

Public Sub InsertDashes()
Dim C As Range
For Each C In Selection
If C.Value Like "################" Then
C.Value = Format(C.Value, "@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@")
End If
Next
End Sub


2) You want to type in the 16-digit number and have it change to the format
you want when you enter it. Add this Worksheet Change event to the code
window for the sheet where you will be entering your "numbers" (right-click
on that sheet's tab and select View Code from the popup menu)...

Private Sub Worksheet_Change(ByVal Target As Range)
Const ColumnToChange As String = "A"
If Target.Column = Asc(ColumnToChange) - 64 Then
If Target.Value Like "################" Then
Application.EnableEvents = False
Target.Value = Format(Target.Value, "@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@")
Application.EnableEvents = True
End If
End If
End Sub


Rick



"CNB Cheryl" <CNB wrote in message
...
I need to have a 16 digit number with - between each number. I created a
custom format, however the 16th digit always reverts to 0 (zero). I need
this to accept all the numbers that are entered into the field. We are on
a
deadline so any help is appreciated. I have tried comma's and other
items,
but no go...

Thanks
CNBCheryl