title: vba excel conditional formatting - invalid Procedure call or argument
body: <p>I have an Excel sheet in which I want to add an Conditional Formula by VBA. While I'm trying to do so, Excel is throwing &quot;Invalid procedure call or argument&quot; and I can't find why.</p>
  <p>The problem is with exactly this line:</p>
  <pre><code>Set cf = shG.Range(&quot;E&quot; &amp; (i - 3) &amp; &quot;:AI&quot; &amp; (i - 2)).FormatConditions.Add(type:=xlExpression, Formula1:=&quot;=OR(ISNUMBER(SEARCH(&quot;&quot;holiday&quot;&quot;,E$&quot; &amp; i &amp; &quot;)),ISNUMBER(SEARCH(&quot;&quot;l4&quot;&quot;,E$&quot; &amp; i &amp; &quot;)))&quot;)
  </code></pre>
  <p>What it should do?</p>
  <blockquote>
  <p>It should change font color to white for 1st and 2nd rows in case if 4th row will contain &quot;holiday&quot; or &quot;l4&quot;</p>
  </blockquote>
  <p>Full Sub:</p>
  <pre><code>Sub AddCondForm(shG As Worksheet)
      Dim r As Range
      Dim cf
      Set r = shRoles.Cells(2, 1)
      Do
          For i = 8 To 204 Step 4
              If Not IsEmpty(shRoles.Cells(r.row, 2)) Then
                  Set cf = shG.Range(&quot;E&quot; &amp; i &amp; &quot;:AI&quot; &amp; i).FormatConditions.Add(type:=xlTextString, String:=r.Value, _
                  TextOperator:=xlBeginsWith)
              Else
                  Set cf = shG.Range(&quot;E&quot; &amp; i &amp; &quot;:AI&quot; &amp; i).FormatConditions.Add(type:=xlCellValue, Operator:=xlEqual, _
                  Formula1:=r.Value)
              End If
              cf.Interior.Color = r.Next.Next.Next.Interior.Color
              cf.Font.Color = r.Next.Next.Next.Font.Color
              cf.SetFirstPriority
  
  'HERE IS PROBLEM
  
              Set cf = shG.Range(&quot;E&quot; &amp; (i - 3) &amp; &quot;:AI&quot; &amp; (i - 2)).FormatConditions.Add(type:=xlExpression, Formula1:=&quot;=OR(ISNUMBER(SEARCH(&quot;&quot;holiday&quot;&quot;,E$&quot; &amp; i &amp; &quot;)),ISNUMBER(SEARCH(&quot;&quot;l4&quot;&quot;,E$&quot; &amp; i &amp; &quot;)))&quot;)
  
  'END OF PROBLEM
                  cf.Font.ColorIndex = 2 
                  'Coloring C Column 
                  Set cf = shG.Range(&quot;C&quot; &amp; (i - 3) &amp; &quot;:C&quot; &amp; i).FormatConditions.Add(type:=xlExpression, Formula1:=&quot;=$A$&quot; &amp; i - 3 &amp; &quot;=1&quot;)
                  cf.Interior.ThemeColor = xlThemeColorAccent6
                  Set cf = shG.Range(&quot;C&quot; &amp; (i - 3) &amp; &quot;:C&quot; &amp; i).FormatConditions.Add(type:=xlExpression, Formula1:=&quot;=$A$&quot; &amp; i - 3 &amp; &quot;=3/4&quot;)
                  cf.Interior.ThemeColor = xlThemeColorAccent6
                  cf.Interior.TintAndShade = 0.2
                  Set cf = shG.Range(&quot;C&quot; &amp; (i - 3) &amp; &quot;:C&quot; &amp; i).FormatConditions.Add(type:=xlExpression, Formula1:=&quot;=$A$&quot; &amp; i - 3 &amp; &quot;=1/2&quot;)
                  cf.Interior.ThemeColor = xlThemeColorAccent6
                  cf.Interior.TintAndShade = 0.4
                  Set cf = shG.Range(&quot;C&quot; &amp; (i - 3) &amp; &quot;:C&quot; &amp; i).FormatConditions.Add(type:=xlExpression, Formula1:=&quot;=$A$&quot; &amp; i - 3 &amp; &quot;=1/4&quot;)
                  cf.Interior.ThemeColor = xlThemeColorAccent6
                  cf.Interior.TintAndShade = 0.6
              Next
              Set r = shRoles.Cells(r.row + 1, 1)
          Loop Until IsEmpty(r.Value)
      End Sub
  </code></pre>
  <p>PS. I checked the formula itself and it seems working properly. Other lines are also working well. Only this one and I don't know why :'(</p>