+ Reply to Thread
Results 1 to 3 of 3

Concatenate selected columns

Hybrid View

  1. #1
    Registered User
    Join Date
    10-11-2012
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    2

    Concatenate selected columns

    I need code to concatenate multiple columns selected by user. User selected columns must be concatenated from first to last row into a first empty column. I have spent days thinking this but I can't find solution to return address of many selected columns...

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Concatenate selected columns

    One way could be this.

    You could use the following VBA function which joins (concatenates) the values from an arbitrary range of cells, with an optional delimiter.

    Public Function Join(source As Range, Optional delimiter As String)
        Dim text As String
        Dim cell As Range: For Each cell In source.Cells
            If cell.Value = "" Then GoTo nextCell
    
            text = text & cell.Value & delimiter
    
    nextCell:
        Next cell
    
        If text <> "" And delimiter <> "" Then
            text = Mid(text, 1, Len(text) - Len(delimiter))
        End If
    
        Join = text
    End Function
    For an example of how to use the function, enter =JOIN(A1:D1) into a cell anywhere on the spreadsheet.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Registered User
    Join Date
    10-11-2012
    Location
    Finland
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Concatenate selected columns

    I've done this with userform and there is a limit of 5 columns to be handled. My latest "creation" is now attached for enhancing.
    Attached Files Attached Files
    Last edited by verokarhu; 01-13-2013 at 01:26 PM.

+ 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