+ Reply to Thread
Results 1 to 5 of 5

Concatenate Strings in each cell

Hybrid View

excelkeechak Concatenate Strings in each... 04-22-2009, 10:48 AM
Paul Re: Concatenate Strings in... 04-22-2009, 11:08 AM
excelkeechak Re: Concatenate Strings in... 04-22-2009, 11:20 AM
Paul Re: Concatenate Strings in... 04-22-2009, 11:45 AM
Phil_V Re: Concatenate Strings in... 04-22-2009, 11:40 AM
  1. #1
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Concatenate Strings in each cell

    hi, i want to concatenate each cell in a range.how would i do it.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Concatenate Strings in each cell

    Hi Excelkeechak,

    Can you provide a bit more detail about your situation? For example, do you have two or more columns of data (let's say A, B and C) and you want to concatenate A1, B1 and C1, then A2, B2 and C2, etc.? Or is your setup different?

    Once you give us a direction we'll be able to provide specific help.

    In general, you can concatenate fields using worksheet functions in a couple ways:

    =CONCATENATE(A1,B1,C1) <--- This would concatenate A1:C1 with no spaces

    or

    =A1&B1&C1 <--- This would concatenate A1:C1 with no spaces

    or

    =A1&" "&B1&" "&C1 <--- This would concatenate A1:C1 with spaces between each

  3. #3
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Re: Concatenate Strings in each cell

    i know the excel general formula but what i need is.

    A
    Apple
    Boy
    Cat
    Dog
    Egg
    Hen
    etcc..

    I want to concatenate like this using VBA
    Apple, Boy,Cat,etc...(Words or numbers separated using Comma)

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Concatenate Strings in each cell

    Two ways, one using formulas, the other using VBA:

    Using Formulas:
    In B1 put the formula =A1
    In B2 put the formula =B1&","&A2
    Fill the formula in B2 as far down as you have values in column A. The string in column B will keep getting longer as it adds the new cells values from column A. Once at the bottom, copy the last value in column B to another cell, but use PasteSpecial -> Values (otherwise you'll get no result when you delete all the other unnecessary values above in column B).

    Using VBA:
    Right-click on the worksheet tab with your values and select 'View Code'
    Paste the following code into the VB Editor window, then close the VB Editor
    Press ALT+F8 then select the "joinData" macro and click Run.

    This macro concatenates every value from A1 to the bottom of column A, using a comma as the delimiter. It then inserts the result into cell B1 as one long string. You can obviously adjust the code to suit your needs.
    Sub joinData()
    Dim myVals() As String, output as String
    Dim i As Long, N As Long
    
    N = Sheets("Sheet1").Range("A65536").End(xlUp).Row
    ReDim myVals(N - 1)
    For i = 1 To N
        myVals(i - 1) = Cells(i, 1).Value
    Next i
    
    output = Join(myVals, ",")
    Sheets("Sheet1").Range("B1").Value = output
    End Sub

  5. #5
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Concatenate Strings in each cell

    How many rows do you have?

+ 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