• Concatenate many values into string (97 SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Concatenate many values into string (97 SR2)

    Author
    Topic
    #370935

    I have a list of 50+ values in a column. I want to concatenate them all into a string, with single quote around each value and commas separating them. For example, I want this list to become the string below it.

    100390
    140588
    141621

    ‘100390’, ‘140588’, ‘141621’

    I’ve looked at the help for the concatenate function and it looks like I would have to select each cell individually to get text between them. With over 50 values, this would take as long as typing them all in! How can I do this quickly?

    Viewing 2 reply threads
    Author
    Replies
    • #588209

      You can write a user-defined function

      Function ConcatenateRange(aRange As Range) As String
      Dim aCell As Range
      Dim strReturn As String
      For Each aCell In aRange
      strReturn = strReturn & “, ‘” & aCell.Value & “‘”
      Next aCell
      If strReturn “” Then
      strReturn = Mid$(strReturn, 3)
      End If
      ConcatenateRange = strReturn
      End Function

      and then use the following formula in a cell:

      =ConcatenateRange(A1:A55)

    • #588336

      A non-macro solution:

      Assuming your list starts on A2.

      on B2 enter:

      =”‘” & A2 & “‘”

      on B3 enter:

      =B2 & “,'” & A3 & “‘”

      Copy B3 down to fit the number of columns.

    • #588725

      Use:

      =”‘”&MCONCAT(A1:A50,”‘,'”)&”‘”

      MCONCAT is a function (among many others) available in Longre’s Morefunc add-in, which is downloadable from:

      http://longre.free.fr/english/index.html%5B/url%5D

    Viewing 2 reply threads
    Reply To: Reply #588209 in Concatenate many values into string (97 SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel