+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Valued Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2007
    Posts
    332

    Replace every other space in a string with "|"

    Hello all,
    I need to programatically replace every other space in a cell with a pipe symbol, in order to seperate stock symbols and their market indicators from each other. For example, right now I have 3,500 rows with data that looks like this:
    BBCA IJ BZG2 GR PBCRF US

    which I need to turn into this
    BBCA IJ | BZG2 GR | PBCRF US

    The length of the tickers is unpredicatble, but the pattern is consistent.

    Any ideas?
    Thanks!
    Last edited by JP Romano; 03-11-2010 at 10:50 AM. Reason: Resolved

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,135

    Re: Replace every other space in a string with "|"

    Code:
    Function OddPipes(s As String) As String
        Dim astr()      As String
        Dim i           As Long
    
        astr = Split(s, " ")
        For i = 1 To UBound(astr) - 1 Step 2
            astr(i) = astr(i) & " |"
        Next i
    
        OddPipes = Join(astr, " ")
    End Function
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2007
    Posts
    332

    Re: Replace every other space in a string with "|"

    Shg, you continue to amaze me, and as a result, I amaze my manager (being that I take full credit for whatever I can). YOU ROCK

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.2.0