+ Reply to Thread
Results 1 to 4 of 4

Single formula

Hybrid View

  1. #1
    Registered User
    Join Date
    03-09-2009
    Location
    World
    MS-Off Ver
    Excel 2003
    Posts
    6

    Single formula

    Hi,

    I would like to take the following entry in a cell xxxx.xxxx.xxxx and change it to xx:xx:xx:xx:xx:xx

    For example Cell A1 contains 001C.234F.E293
    I want Cell B1 to contain the same value but formatted this way 00:1C:23:4F:E2:93

    I need to replace the full stops with ":" - but may not be necessary with the next requirement
    I need every 2nd character to be preceeded with ":"

    I can't seem to make a single formula that will do this in one go. I will have 1,000's of these to so hence the need for a formula.

    Any help is greatly appreciated.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Single formula

    Not very elegant but try
    =SUBSTITUTE(MID(A1,1,2)&":"&MID(A1,3,5)&":"&MID(A1,8,5)&":"&MID(A1,13,2),".",":")
    Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    03-09-2009
    Location
    World
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Single formula

    Hi,

    that does the trick. I forgot to look at the subsitute function. Many thanks for the quick reply.

  4. #4
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Single formula

    Hi

    Function InsertSymbol(TxtString As String, Symbol As String, _
                                AfterEvery As Integer) As String
        Dim j As Integer
        Dim NewString As String
    
        For j = 1 To Len(TxtString) Step AfterEvery
            NewString = NewString & Mid(TxtString, j, AfterEvery) & Symbol
        Next j
    
        InsertSymbol = Left(NewString, Len(NewString) - 1)
    
    End Function
    How to use:
    1. Copy above code.
    2. In Excel press Alt + F11 to enter the VBE.
    3. Press Ctrl + R to show the Project Explorer.
    4. Choose Insert -> Module.
    5. Paste code into the right pane.
    6. Press Alt + Q to close the VBE.
    7. Save workbook before any other changes.


    Then use this formula
    =InsertSymbol(SUBSTITUTE(A1,".",""),":",2)
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1