title: How to SUM / merge similar rows in Excel using VBA?
body: <p>I'm trying to build a simple macro in VBA for Excel that would SUM [merge] all the rows that have the same name (value in the first columns).
  So for example </p>
  
  <pre><code>ExampleRowA 1 0 1 1 3 4
  ExampleRowA 2 1 2 2 1 0
  ExampleRowC 9 7 7 7 2 5
  </code></pre>
  
  <p>the result should look like this</p>
  
  <pre><code>ExampleRowA 3 1 3 3 4 4
  ExampleRowC 9 7 7 7 2 5
  </code></pre>
  
  <p>We can assume that the rows that need to be merged are not scattered, and can only appear one after another.</p>
  
  <p>I did something like this, and it almost works, except I have to run it two times.</p>
  
  <pre><code>LastRow = ActiveSheet.UsedRange.Rows.Count
  Set r = ActiveSheet.UsedRange.Resize(1)
  With Application.WorksheetFunction
  
  
       For iRow = 2 To LastRow
          If Cells(iRow, 1) = Cells(iRow + 1, 1) Then
              LastCol = r(r.Count).Column
              SumCol = LastCol + 1
                  For iCol = 2 To SumCol
                  Cells(iRow, iCol) = .Sum(Range(Cells(iRow, iCol), Cells(iRow + 1, iCol)))
                  Next iCol
              Rows(iRow + 1).Delete
          End If
       Next iRow
  
  End With
  </code></pre>
  
  <p>I've done some programming in other scripting languages but am new to VB/VBA and don't know the possibilites/limitations of it.</p>
  
  <p>In other languages I would probably use arrays but I don't get the way they work here. I can't deny that because of time constraints I prefer to learn by analyzing examples rather than reading a 500+ page VBA Bible.</p>