+ Reply to Thread
Results 1 to 9 of 9

inserting colon

  1. #1
    Registered User
    Join Date
    05-30-2005
    Posts
    38

    Unhappy inserting colon

    this is the data
    0014f8c49563

    how to insert colon automaticaly in every 2nd character

    output is >>> 00:14:f8:c4:95:63

  2. #2
    RB Smissaert
    Guest

    Re: inserting colon

    Something like this will do it:

    Function InsertCharsInString(strString As String, _
    strInsert As String, _
    lInterval As Long) As String

    Dim lStart As Long
    Dim strNew As String

    lStart = -1

    strNew = strString

    Do While lStart < Len(strNew) - (lInterval + 1)
    lStart = lStart + lInterval + 1
    strNew = Left$(strNew, lStart) & _
    strInsert & _
    Mid$(strNew, lStart + 1)
    Loop

    InsertColons = strNew

    End Function


    Sub test()

    MsgBox InsertColons("0014f8c49563", ":", 2)

    End Sub


    RBS


    "xtrmhyper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > this is the data
    > 0014f8c49563
    >
    > how to insert colon automaticaly in every 2nd character
    >
    > output is >>> 00:14:f8:c4:95:63
    >
    >
    > --
    > xtrmhyper
    > ------------------------------------------------------------------------
    > xtrmhyper's Profile:
    > http://www.excelforum.com/member.php...o&userid=23851
    > View this thread: http://www.excelforum.com/showthread...hreadid=556466
    >



  3. #3
    RB Smissaert
    Guest

    Re: inserting colon

    Test Sub should of course be:

    Sub test()

    MsgBox InsertCharsInString("0014f8c49563", ":", 2)

    End Sub

    RBS


    "RB Smissaert" <[email protected]> wrote in message
    news:[email protected]...
    > Something like this will do it:
    >
    > Function InsertCharsInString(strString As String, _
    > strInsert As String, _
    > lInterval As Long) As String
    >
    > Dim lStart As Long
    > Dim strNew As String
    >
    > lStart = -1
    >
    > strNew = strString
    >
    > Do While lStart < Len(strNew) - (lInterval + 1)
    > lStart = lStart + lInterval + 1
    > strNew = Left$(strNew, lStart) & _
    > strInsert & _
    > Mid$(strNew, lStart + 1)
    > Loop
    >
    > InsertColons = strNew
    >
    > End Function
    >
    >
    > Sub test()
    >
    > MsgBox InsertColons("0014f8c49563", ":", 2)
    >
    > End Sub
    >
    >
    > RBS
    >
    >
    > "xtrmhyper" <[email protected]> wrote
    > in message news:[email protected]...
    >>
    >> this is the data
    >> 0014f8c49563
    >>
    >> how to insert colon automaticaly in every 2nd character
    >>
    >> output is >>> 00:14:f8:c4:95:63
    >>
    >>
    >> --
    >> xtrmhyper
    >> ------------------------------------------------------------------------
    >> xtrmhyper's Profile:
    >> http://www.excelforum.com/member.php...o&userid=23851
    >> View this thread:
    >> http://www.excelforum.com/showthread...hreadid=556466
    >>

    >



  4. #4
    Registered User
    Join Date
    05-30-2005
    Posts
    38

    Unhappy inserting colon

    i dont any idea for that command

    any formula in excel?


    tnx in advace

  5. #5
    NickHK
    Guest

    Re: inserting colon

    There is no command in Excel, that's why you need to write your own.

    Make that code a Public Function in a module, then you can call it from the
    worksheet with:
    e.g. in cell A1, "=InsertCharsInString("0014f8c49563", ":", 2)"

    Google for "Excel User defined function", you get a lot of help.

    NickHK

    "xtrmhyper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > i dont any idea for that command
    >
    > any formula in excel?
    >
    >
    > tnx in advace
    >
    >
    > --
    > xtrmhyper
    > ------------------------------------------------------------------------
    > xtrmhyper's Profile:

    http://www.excelforum.com/member.php...o&userid=23851
    > View this thread: http://www.excelforum.com/showthread...hreadid=556466
    >




  6. #6
    Registered User
    Join Date
    05-30-2005
    Posts
    38

    inserting colon

    tnx anyway?

    how about concatenate?

  7. #7
    Andrew Taylor
    Guest

    Re: inserting colon

    If you know the string will be exactly 12 bytes long then you
    can use the worksheet formula :

    =MID(A1,1,2)&":"&MID(A1,3,2)&":"&MID(A1,5,2)&":"&MID(A1,7,2)&":"&MID(A1,9,2)&":"&MID(A1,11,2)


    NickHK wrote:
    > There is no command in Excel, that's why you need to write your own.
    >
    > Make that code a Public Function in a module, then you can call it from the
    > worksheet with:
    > e.g. in cell A1, "=InsertCharsInString("0014f8c49563", ":", 2)"
    >
    > Google for "Excel User defined function", you get a lot of help.
    >
    > NickHK
    >
    > "xtrmhyper" <[email protected]> wrote
    > in message news:[email protected]...
    > >
    > > i dont any idea for that command
    > >
    > > any formula in excel?
    > >
    > >
    > > tnx in advace
    > >
    > >
    > > --
    > > xtrmhyper
    > > ------------------------------------------------------------------------
    > > xtrmhyper's Profile:

    > http://www.excelforum.com/member.php...o&userid=23851
    > > View this thread: http://www.excelforum.com/showthread...hreadid=556466
    > >



  8. #8
    NickHK
    Guest

    Re: inserting colon

    Concatenate what ?

    NickHK

    "xtrmhyper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > tnx anyway?
    >
    > how about concatenate?
    >
    >
    > --
    > xtrmhyper
    > ------------------------------------------------------------------------
    > xtrmhyper's Profile:

    http://www.excelforum.com/member.php...o&userid=23851
    > View this thread: http://www.excelforum.com/showthread...hreadid=556466
    >




  9. #9
    Registered User
    Join Date
    05-30-2005
    Posts
    38

    Thumbs up inserting colon

    tnx
    Andrew Taylor

    it works

    GOD SPEED

+ 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