title: How to concatenate unique values in column B by singular values in column A
body: <p>I have two columns representing a 1:many relationship. I need to reduce this down to a 1:1 relationship where the many in columnn B are concatenated by commas. Data below:</p>
  
  <pre>
  zipcode neighbors
  10001   10010
  10001   10011
  10001   10016
  10001   10018
  10001   10119
  10001   10199
  10003   10012</pre>
  
  <p>Here is what I want the output to look like:  </p>
  
  <pre>
  zipcode neighbors
  10001   10010, 10011, 10012, 10016, 10018, 10019, 10199</pre>
  
  <p>There are 9000 records so I need to run a loop until end of record.</p>
  
  <p>Now sure how to do this.</p>
  
  <hr>
  
  <p>I figured it out, thanks everyone. Code share below:</p>
  
  <pre><code>Sub Concatenate()
  
  Dim oldValue As String
  Dim newValue As String
  Dim result As String
  Dim counter As Integer
  
  oldValue = ""
  newValue = ""
  result = ""
  counter = 1
  
  For i = 2 To 9401
  
  newValue = Worksheets("data").Cells(i, 1)
  
  If (oldValue &lt;&gt; newValue) Then
  
      Worksheets("result").Cells(counter, 1).NumberFormat = "@"
      Worksheets("result").Cells(counter, 2).NumberFormat = "@"
      Worksheets("result").Cells(counter, 1) = oldValue
      Worksheets("result").Cells(counter, 2) = result
      counter = counter + 1
      result = ""
  
  End If
  
  If (result = "") Then
      result = Worksheets("data").Cells(i, 2)
  Else
      result = result + "," + Worksheets("data").Cells(i, 2)
  End If
  
  oldValue = newValue
  
  Next i
  
  
  End Sub
  </code></pre>