title: Is it possible to combine three rows having the same color together?
body: <p>Here is an <a href="https://i.stack.imgur.com/YWOzl.png" rel="nofollow noreferrer">Image to support explanation</a>.  </p>
  
  <p>Column D values are highlighted with the same color if the entries are identical in this column. </p>
  
  <p>In this case, for each "group" of color I should:</p>
  
  <ul>
  <li>add all the values of column E for a given color and enter the amount in the column J.</li>
  </ul>
  
  <p>As you see in the picture, the amount in the column <code>J</code> is perfect when the given color occurs only in two rows (works perfectly for color red and green). 
  But as soon as the color covers more than two rows, the sum doesn't reflect the sum of all the rows, but the sum of two entries at a time only. </p>
  
  <p>Here is the code I wrote for this calculation:</p>
  
  <pre><code>Sub test()
  
      Dim LastRow As Long, I As Long, j As Long
      Dim arr As Variant
      Dim Total_Payments As Single
      Dim Total_CashBalance As Single
  
      With ThisWorkbook.Worksheets("Master")
  
          'Find Last row of column L
          LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
  
          'Set array starting from row 2 to LastRow of column L
          arr = .Range("D2:D" &amp; LastRow)
  
          For I = LBound(arr) To UBound(arr)
  
              If .Range("D" &amp; I).Interior.Pattern &lt;&gt; xlNone Then
  
                  For j = LBound(arr) To UBound(arr)
  
                      If (.Range("D" &amp; j).Interior.Pattern &lt;&gt; xlNone) And (I &lt;&gt; j) Then
  
                          If .Range("D" &amp; I).Interior.Color = .Range("D" &amp; j).Interior.Color Then
  
  
                                  .Range("N" &amp; I).Value = "Cell L" &amp; I &amp; " has the same background color with cell/s L" &amp; j
  
                                  Total_Payments = .Range("E" &amp; I).Value + .Range("E" &amp; j).Value
                                  Range("J" &amp; I).Value = Total_Payments
  
                          End If
  
                      End If
  
                  Next j
  
              End If
  
          Next I
  
      End With
  
  End Sub
  </code></pre>
  
  <p>I would be really happy if you could tell me how to make this work for a number of cells in one group greater than 2 :) Thank you!! </p>