Results 1 to 2 of 2

Concatenate non-blank values in the same column and add commas

Threaded View

chris.huang Concatenate non-blank values... 06-26-2013, 08:02 PM
JBeaucaire Re: Concatenate non-blank... 06-26-2013, 08:52 PM
  1. #1
    Registered User
    Join Date
    06-26-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2003
    Posts
    1

    Concatenate non-blank values in the same column and add commas

    Hi,

    I would like to concatenate all rows in the same column into one string, separated by comma and ignore all the blank cells. The code I have below will concatenate values across columns, but I actually want to concatenate values in the same column. Thanks in advance!

    Chris

    Desired:
    A........B.......C
    1........3........4
    2........5........6
    1,2.....3,4.....4,6

    Code execution give me this:
    A........B.......C
    1........3........4 --> 1,3,4
    2........5........6 --> 2,5,6


    ------------------------------------------------------------
    Sub Concat()
      Dim UpperLeft As Range
      Dim Concat As String
    
      Set UpperLeft = Range("A1")
    
      For i = 0 To 9
        Concat = ""
        For j = 0 To 25
          UpperLeft.Offset(i, j).Select
          If UpperLeft.Offset(i, j).Value <> "" Then
            If Concat <> "" Then Concat = Concat & ","
            Concat = Concat & UpperLeft.Offset(i, j).Value
          End If
        Next j
        UpperLeft.Offset(i, 0).Value = Concat
      Next i
    End Sub
    Last edited by JBeaucaire; 06-26-2013 at 08:46 PM. Reason: Added CODE tags, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

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