title: set custom sum-by-color formula in vba
body: <pre><code>Sub sumexeptblack()
  
      For Each cell In Range("4:4")
        If cell.Font.Color &lt;&gt; 0 Then
           Range("A3").Value = Range("A3").Value + cell.Value
        End If
      Next cell
  
  End Sub
  </code></pre>
  
  <p>I write this code and it works, but when I just put it on another loop excel just calculating without any error or results. the second code is:</p>
  
  <pre><code>Sub sumallrowcolored()
      Dim i As Integer
      Dim e As Integer
      e = 1
  
      For i = 2 To 168 Step 2
          e = i - e
          For Each cell In Range("i:i")
             If cell.Font.Color &lt;&gt; 0 Then
                Range("Ae").Value = Range("Ae").Value + cell.Value
             End If
          Next cell
      Next i
  
  End Sub
  </code></pre>