#1   Report Post  
Posted to microsoft.public.excel.misc
iggy10284
 
Posts: n/a
Default Custom cell formats


I am trying to create a custom format for my account numbers. An example
of one of the account numbers is 9500-01-010-02-010-000-00. I want to be
able to enter just numbers and have the dashes be put in automatically,
but here is the kicker.... I also need it to fill spots with zero if no
data is entered. So if I enter 9500 it will appear as
9500-00-000-00-000-000-00. Any help would be greatly appreciated.


--
iggy10284
------------------------------------------------------------------------
iggy10284's Profile: http://www.excelforum.com/member.php...o&userid=32078
View this thread: http://www.excelforum.com/showthread...hreadid=518291

  #2   Report Post  
Posted to microsoft.public.excel.misc
Sloth
 
Posts: n/a
Default Custom cell formats

You won't be able to do what you want. Numbers can only be 15 digits long.
No exceptions. I believe you will have to enter the account number as text
and include the dashes. If you had a shorter account number you might be
able to do it, but it would fill in the left with zeros, not the right.

"iggy10284" wrote:


I am trying to create a custom format for my account numbers. An example
of one of the account numbers is 9500-01-010-02-010-000-00. I want to be
able to enter just numbers and have the dashes be put in automatically,
but here is the kicker.... I also need it to fill spots with zero if no
data is entered. So if I enter 9500 it will appear as
9500-00-000-00-000-000-00. Any help would be greatly appreciated.


--
iggy10284
------------------------------------------------------------------------
iggy10284's Profile: http://www.excelforum.com/member.php...o&userid=32078
View this thread: http://www.excelforum.com/showthread...hreadid=518291


  #3   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey
 
Posts: n/a
Default Custom cell formats

That's not something that formatting alone can handle.

In addition, since your account numbers are 19 digits long, the entry
cells will have to be preformatted as text or else entries longer than
15 digits will be truncated (or you could prefix them with an
apostrophe), so no number formatting will be applied.


You can put this in the worksheet code module (right-click the worksheet
tab and choose View Code). Change the column to suit:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sZEROS As String = "0000000000000000000"
Const sSEP As String = "-"
Const sNUMFORMAT As String = "@"
Const nTARGETCOL As Long = 1 'A
Dim vDigits As Variant
Dim sInput As String
Dim sOutput As String
Dim nStart As Long
Dim i As Long
With Target
If .Count 1 Then Exit Sub
If .Column = nTARGETCOL Then
vDigits = Array(4, 2, 3, 2, 3, 3, 2)
sInput = Left(.Text & sZEROS, 19)
nStart = 1
For i = LBound(vDigits) To UBound(vDigits)
sOutput = sOutput & sSEP & _
Mid(sInput, nStart, vDigits(i))
nStart = nStart + vDigits(i)
Next i
On Error Resume Next
Application.EnableEvents = False
.NumberFormat = sNUMFORMAT
.Value = Mid(sOutput, 2)
Application.EnableEvents = True
On Error GoTo 0
End If
End With
End Sub


In article ,
iggy10284
wrote:

I am trying to create a custom format for my account numbers. An example
of one of the account numbers is 9500-01-010-02-010-000-00. I want to be
able to enter just numbers and have the dashes be put in automatically,
but here is the kicker.... I also need it to fill spots with zero if no
data is entered. So if I enter 9500 it will appear as
9500-00-000-00-000-000-00. Any help would be greatly appreciated.

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
Urgent date/scheduling calc needed jct Excel Worksheet Functions 3 February 24th 06 01:36 AM
Reference Cell in custom format???? lil_ern63 Excel Discussion (Misc queries) 3 September 1st 05 02:27 PM
Changing Cell formats to date fields automatically PCLIVE Excel Worksheet Functions 3 April 12th 05 10:34 PM
How do I format a cell for a custom part number? PJ Excel Discussion (Misc queries) 4 March 3rd 05 03:57 AM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


All times are GMT +1. The time now is 03:40 PM.

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

About Us

"It's about Microsoft Excel"