title: Excel VBA to concatenate data from multiple rows into 1 row
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3961436/excel-concatenate-rows">Excel Concatenate Rows</a>  </p>
  </blockquote>
  
  
  
  <p>I want to merge several rows of data into a single row with an Excel VBA macro, and for the output to be on a new worksheet, but I don't know where to start.  The data is fairly simple, and consists of a column of IDs and a column of products.  There may be multiple lines with the same ID if multiple products entries exist, so I'm looking for a macro to loop through the dataset and merge these multiple entries into one.  If the row is unique (i.e. there is only one product entry against that ID) then the row can just be copied to the output sheet without any merging.</p>
  
  <p>The data looks like this:</p>
  
  <hr>
  
  <pre><code>ID          PRODUCT
  
  1-10OOMD6   Product SKU1 (9000)
  
  1-10PQFV3   Product SKU2 (7000)
  
  1-10QSCSB   Product SKU3 (50)
  
  1-10RWX7L   Product SKU4 (2)
  
  1-10TKZQJ   Product SKU5 (1)
  
  1-10UROIL   Product SKU3 (12000)
  
  1-10UROIL   Product SKU7 (12000)
  
  1-10UROIL   Product SKU8 (12000)
  
  1-10UW6KU   Product SKU9 (1000)
  
  1-10UW6KU   Product SKU10 (6500)
  
  1-10W5HR9   Product SKU11 (80)
  
  1-10XZWX7   Product SKU12 (1)
  
  1-10ZRXVJ   Product SKU5 (70)
  
  1-10ZV49V   Product SKU3 (250)
  
  1-110RQQN   Product SKU13 (1)
  
  1-110RQQN   Product SKU2 (600)
  
  1-110RQQN   Product SKU14 (1)
  
  1-110RQQN   Product SKU4 (600)
  
  1-112DJ2N   Product SKU15 (5)
  
  1-112EWRQ   Product SKU16 (3000)
  </code></pre>
  
  <hr>
  
  <p>And I want it to end up like this:</p>
  
  <hr>
  
  <pre><code>ID  PRODUCT
  
  1-10OOMD6   Product SKU1 (9000)
  
  1-10PQFV3   Product SKU2 (7000)
  
  1-10QSCSB   Product SKU3 (50)
  
  1-10RWX7L   Product SKU4 (2)
  
  1-10TKZQJ   Product SKU5 (1)
  
  1-10UROIL   Product SKU3 (12000), Product SKU7 (12000), Product SKU8 (12000)
  
  1-10UW6KU   Product SKU9 (1000),Product SKU10 (6500)
  
  1-10W5HR9   Product SKU11 (80)
  
  1-10XZWX7   Product SKU12 (1)
  
  1-10ZRXVJ   Product SKU5 (70)
  
  1-10ZV49V   Product SKU3 (250)
  
  1-110RQQN   Product SKU13 (1), Product SKU2 (600), Product SKU14 (1), Product SKU4 (600)
  
  1-112DJ2N   Product SKU15 (5)
  
  1-112EWRQ   Product SKU16 (3000)
  </code></pre>
  
  <hr>
  
  <p>So that each ID on the output sheet is unique.</p>
  
  <p>A few points:</p>
  
  <ul>
  <li>I couldn't paste images, so to clarify: this is an ID: 1-10OOMD6, and this is a product: Product SKU1 (9000)</li>
  <li>The dataset is large, at least 35,000 rows</li>
  <li>The data isn't initially sorted by ID, but easily can be. </li>
  <li>It would be great to separate the products with a comma. </li>
  <li>I would like to output of the macro on another worksheet.</li>
  </ul>
  
  <p>Any help would be greatly appreciated!  This would save me an enormous amount of time!
  Thank you.</p>