+ Reply to Thread
Results 1 to 4 of 4

Combine comma separated strings

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-14-2007
    Location
    Chester, England
    MS-Off Ver
    2010 & 2016
    Posts
    312

    Combine comma separated strings

    Hi

    I am trying to work out if there is an easy way to combine multiple comma separated strings to make one string. The only thing I can think of is to try and write some extremely long winded code that would split out to columns and then use if statements to put stuff back together as one.

    As an example the original strings would look something like this.
    1ABCD,,000001,,,Test,,Check,,,,,
    1ABCD,,000001,Red,,,,,,,,,
    1ABCD,,000001,,,Test,Test2,,,,,,

    And the result would be.
    1ABCD,,000001,Red,,Test,Test2,Check,,,,,

    The number of commas could be different each time this is run but for the strings being compared the number of commas would always match. If anyone has any suggestions as to how this could be acheived that would be great.

    Thanks in advance

    Jim
    Last edited by JimmyA; 11-09-2016 at 12:37 PM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Combine comma separated strings

    Try:
    Sub CombineStrings()
        Dim i As Integer
        Dim j As Integer
        Dim sIn() As String
        Dim sTemp() As String
        Dim sOut() As String
        Dim sOutput As String
        
        ReDim sIn(1 To 3)
        sIn(1) = "1ABCD,,000001,,,Test,,Check,,,,,"
        sIn(2) = "1ABCD,,000001,Red,,,,,,,,,"
        sIn(3) = "1ABCD,,000001,,,Test,Test2,,,,,,"
        
        For i = LBound(sIn) To UBound(sIn)
            sTemp = Split(sIn(i), ",")
            ReDim Preserve sOut(UBound(sTemp))
            For j = LBound(sTemp) To UBound(sTemp)
                If sOut(j) = "" Then sOut(j) = sTemp(j)
            Next j
        Next i
        sOutput = Join(sOut, ",")
        Debug.Print sOutput
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    02-14-2007
    Location
    Chester, England
    MS-Off Ver
    2010 & 2016
    Posts
    312

    Re: Combine comma separated strings

    Hi Olly

    Thank you very much for this. This is exactly what I was after.

    I just need to read up now so I understand how!! :-)

    Thanks again

    Jim

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Combine comma separated strings

    Happy to help. If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. You can also 'Add Reputation' to those who helped you. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Extract Value Separated by Comma
    By bluesora in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-19-2015, 11:15 AM
  2. Help with comma separated delimiters (I think)
    By runnercyclist in forum Excel General
    Replies: 1
    Last Post: 12-05-2014, 09:37 AM
  3. [SOLVED] How to extract strings from hyphen separated strings
    By sharathnarayanan in forum Excel General
    Replies: 5
    Last Post: 11-22-2014, 10:01 AM
  4. Combine multiple rows into one comma separated column
    By NotAvg1 in forum Excel General
    Replies: 9
    Last Post: 03-04-2013, 07:06 PM
  5. Comma Separated Value
    By matrixknow in forum Excel General
    Replies: 2
    Last Post: 05-22-2007, 07:10 AM
  6. Comma Separated - Help Please
    By endit in forum Excel General
    Replies: 2
    Last Post: 10-11-2006, 06:11 AM
  7. [SOLVED] combine rows into one cell separated by comma
    By Miki Jo in forum Excel General
    Replies: 2
    Last Post: 03-09-2006, 04:30 PM

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