title: Excel VBA create report with grouped values
body: <p>I'm trying to create a report in Excel using VBA to process some data and create a tabular report that summarizes the values by group.  Although I can generate the table manually, I can't get the code to fully create this report.</p>
  
  <p>Input data:</p>
  
  <pre><code>ID | name   | number | class | comment
  ---|--------|--------|-------|----------       
   1 | john   |      4 | A1    | sports
  ---|--------|--------|-------|----------      
   1 | john   |      3 | A2    | sports
  ---|--------|--------|-------|----------      
   1 | john   |      5 | A3    | sports
  ---|--------|--------|-------|----------      
   2 | charly |      1 | B3    | tech
  ---|--------|--------|-------|----------     
   2 | charly |      2 | B2    | tech
  ---|--------|--------|-------|----------  
   2 | charly |      1 | B2    | tech
  ---|--------|--------|-------|----------   
   3 | frank  |      7 | C3    | language
  ---|--------|--------|-------|----------     
   3 | frank  |      2 | C5    | language
  ---|--------|--------|-------|----------  
   3 | frank  |      9 | C4    | language
  </code></pre>
  
  <p>Expected summary in a new worksheet:</p>
  
  <pre><code>ID | name   | number  | class      | comment
  ---|--------|---------|------------|----------
   1 | john   | ”3,4,5” | ”A1,A2,A3” | sports
  ---|--------|---------|------------|----------
   2 | charly | ”1,2”   | ”B2,B3”    | tech
  ---|--------|---------|------------|----------
   3 | frank  | ”2,7,9” | ”C3,C4,C5” | language
  </code></pre>
  
  <p>Here is the code I currently have:</p>
  
  <pre><code>Function Uniques(r As Range)
  
  Dim d As Object, c As Range, tmp
       Set d = CreateObject("scripting.dictionary")
       For Each c In rCells
          tmp = Trim(c.Value)
          If Len(tmp) &gt; 0 Then
               If Not d.Exists(tmp) And tmp &lt;&gt; “HEADER” Then d.Add tmp, 1
          End If
       Next c
       Uniques = d.keysEnd Function
       With .Range("A1:N" &amp; .Cells(.Rows.Count, 1).End(xlUp).Row)
             .AutoFilter Field:=1
             Set a = .Columns(“A”).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
             Set b = .Columns(“B”).Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
             'getting the unique items
              d = Uniques(Range("D:D").SpecialCells(xlCellTypeVisible))
             .AutoFilter
       End With
  </code></pre>