View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein \(MVP - VB\)[_456_] Rick Rothstein \(MVP - VB\)[_456_] is offline
external usenet poster
 
Posts: 1
Default Custom number display format

Here's an example of one that puts the reformatted string in the adjacent
column, but you could also use it as an event-triggered macro, or use it
in
other ways:

================================
Option Explicit
Sub SpecFormat()
Dim c As Range
For Each c In Selection
With c.Offset(0, 1)
.NumberFormat = "@"
.Value = Replace(c.Value, "-", "")
.Value = Left(.Value, 4) & "-" & _
Mid(.Value, 5, 4) & "-" & _
Mid(.Value, 9, 4) & "-" & _
Mid(.Value, 13)
End With
Next c
End Sub
==================


A minor simplification...

Sub SpecFormat()
Dim c As Range
For Each c In Selection
c.Offset(0, 1).Value = Format(Replace(c.Value, "-", ""), _
"0000-0000-0000-0000000")
Next
End Sub

Rick