Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Custom Format on 16 Digit Number

Saved from a previous post:

If you type the value as text (either pre-format the cell or text and then do
the data entry or start your entry with an apostrophe), then you can use this
technique:

Type this in A1:
'1234123412341234

and use this in that helper column:
=mid(a1,1,4)&"-"&mid(a1,5,4)&"-"&mid(a1,9,4)&"-"&mid(a1,13,4)

or you could use a worksheet event that does the work for you--but you still
need to enter the data as text!

If you want to try this idea, rightclick on the worksheet tab that should have
this behavior. Select view code. Paste this into the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myTempVal As Variant

On Error GoTo errhandler:

If Target.Cells.Count 1 Then
Exit Sub
End If

If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End if

If IsNumeric(Target.Value) = False Then
Exit Sub
End If

myTempVal = CDec(Target.Value)
Application.EnableEvents = False
Target.Value = Format(myTempVal, "0000-0000-0000-0000")

errhandler:
Application.EnableEvents = True

End Sub


If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Neil wrote:

Niek:

I don't know of a way to format a text field to insert dashes automatically
does one exist?
--
Neil

"Neil" wrote:

When I try to format a 16 digit number into 1111-2222-3333-4444 the last
number is displayed as a "0". How do I get the last number to display
correctly?
--
Neil


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to format cell to display S("6 digit number here) prem New Users to Excel 3 December 30th 08 01:12 PM
Format divide by 10 / single digit view: Custom? Text(Round( nastech Excel Discussion (Misc queries) 0 June 27th 06 11:03 PM
Create number format for 4 digit integer preceded by zero Headfish Excel Worksheet Functions 6 April 14th 06 08:56 PM
How do i format a 5 to 6 digit number into the correct date? date cell configuration Excel Worksheet Functions 4 June 10th 05 08:07 PM
Cell will not format numbers correctly for a 13 digit custom barc. Laudan Excel Worksheet Functions 4 April 11th 05 08:13 PM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"