Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    NJ, USA
    Posts
    239
    Thanks
    2
    Thanked 1 Time in 1 Post

    Custom cell format? (2000, SR-1)

    Does anybody know if it's possible to use custom cell formats with text fields? I have an 8 character alphanumeric field that I want to display with hyphens, i.e., XX-XXXX-XX. I realise I can do it in a separate cell, but would prefer to display it where it is in the hyphenated format.
    TIA

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Custom cell format? (2000, SR-1)

    If the X's are only numbers, then 00-0000-00 will work as a custom cell format, but since you said that the X's are alphanumeric, I don't think that you can do it with a custom format. Separate cells would be the most straight-forward, but you can use the selection change event. Something like,
    <pre>Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If [A4] <> "" And InStr([A4], "-") = 0 Then
    [A4] = Left([A4], 2) & "-" & Mid([A4], 3, 4) & "-" & Right([A4], 2)
    End If
    End Sub</pre>

    notice that this causes some wierd stuff if you just enter AB in cell A4. It needs alot more error checking. HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •