title: Excel VBA: How to filter a range based on colour and then output the result into SUM
body: <p>I have a function FILTER_COL that's supposed to filter the cells in a range rng which have the same colour as a cell from_cell:</p>
  
  <pre><code>Function FILTER_COL(from_cell As String, rng As Range)
  Dim colour As Integer
  For Each cell In Range(from_cell)
      colour = cell.Interior.ColorIndex
  Next cell
  
  Dim Out As Variant
  For Each cell In rng
      If cell.Interior.ColorIndex = colour Then
          Out.Add (cell.Value)
      End If
  Next cell
  FILTER_COL = Out
  End Function
  </code></pre>
  
  <p>I then put the result into SUM as follows:</p>
  
  <pre><code>SUM(FILTER_COL("A55",K50:K52))
  </code></pre>
  
  <p>It gives a #VALUE! error if there's any cell in the range K50:K52 which has the same colour as A55.</p>