Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Custom Alphanumeric Format

I am sure this is simple, but I just can't figure it out. I want to create a
custom format for a cell with both text and numbers. I want to be able to
type in something like "22111AA" and have it display as "22-111-AA". Can
anyone help? THX.


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Custom Alphanumeric Format

Number formatting will only work on numbers.

You can either use another cell with a formula in it:

=left(a1,2)&"-"&mid(a2,3,3)&"-"&mid(a2,6,2)

Or you could have an event macro...

If you want to try, right click on the worksheet tab that should have this
behavior. Select view code and paste this into the codewindow:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

With Target
'one cell at a time
If .Cells.Count 1 Then Exit Sub
'only column A
If Intersect(Me.Range("A:A"), .Cells) Is Nothing Then Exit Sub

'gotta be 7 characters
If Len(.Value) < 7 Then Exit Sub

On Error GoTo ErrHandler:
Application.EnableEvents = False
.Value = Left(.Value, 2) & "-" _
& Mid(.Value, 3, 3) & "-" & Mid(.Value, 6, 2)
End With

ErrHandler:
Application.EnableEvents = True
End Sub

I check for entries in column A. Change that to the range you want to use.

You can read more about events at:
Chip Pearson's site:
http://www.cpearson.com/excel/events.htm

David McRitchie's site:
http://www.mvps.org/dmcritchie/excel/event.htm

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


tkeith wrote:

I am sure this is simple, but I just can't figure it out. I want to create a
custom format for a cell with both text and numbers. I want to be able to
type in something like "22111AA" and have it display as "22-111-AA". Can
anyone help? THX.


--

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
adding custom format Kelly Excel Discussion (Misc queries) 2 June 29th 06 03:35 PM
Need Custom format, not a formula nastech Excel Discussion (Misc queries) 21 April 29th 06 03:42 AM
Custom Cell Format Bobbie Excel Discussion (Misc queries) 1 December 27th 05 03:42 PM
Custom Number Format Text Frank & Pam Hayes Excel Discussion (Misc queries) 3 December 3rd 05 05:36 PM
Custom Time Format doesn't work for me chuck Excel Discussion (Misc queries) 1 February 13th 05 04:12 AM


All times are GMT +1. The time now is 10:44 AM.

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"