title: Conditional Formatting Excel document via VB6 (issue with overwriting formats)
body: <p>I'm creating an Excel document at runtime that has a bunch of values I'd like to have conditionally formatted. In going through various attempts from scratch as well as using/modifying code outputted from the Excel's macro recorder, I'm having a consistent issue related to formatting overwrites.</p>
  
  <p>I've posted a snippet of the code below and can say that I've tested to ensure my selection ranges are valid and appropriate for what I want conditionally formatted. There is some overlap but what's bizarre is that the first conditional format takes on just one property of the second conditional format. Meaning D5:End of the worksheet ends up having a green color font as opposed to the red it should be. Commenting each section of the code does allow them to work independently but I'm guessing this is an issue with specifying conditional formats further somehow? I've tried a few different case scenarios and below is the code with modifications:</p>
  
  <p>EDIT (Updated Code):</p>
  
  <pre><code>'First conditional format, check sheet for values &gt; 50 and make text red.
  With xl.range("D5:" &amp; theLastColumn &amp; lastRow)
    .FormatConditions.add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=50"
    With .FormatConditions(1).Font
      .Color = -16383844
      .TintAndShade = 0
    End With
    .FormatConditions(1).StopIfTrue = False
  End With
  
  
  'Second conditional format, check specific row (row 5 in the example) 
  'for values &gt; 40, and fill interior with green in addition to dark green text.
  With xl.range("D" &amp; Infectivity &amp; ":" &amp; theLastColumn &amp; Infectivity)
    .FormatConditions.add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=40"
    With .FormatConditions(2).Font
      .Color = -16752384
      .TintAndShade = 0
    End With
    With .FormatConditions(2).Interior
      .PatternColorIndex = xlAutomatic
      .Color = 13561798
      .TintAndShade = 0
    End With
  End With
  </code></pre>
  
  <p>So what's the best way to have multiple conditional formats (that may overlap ranges) and still have them all function as intended? I've tried debugging this so much I'm certain there's something easy I'm overlooking. I've also tried a few different methods to specify separate formatconditions(1) and formatconditions(2) but still receive strange issues.</p>
  
  <p>EDIT:</p>
  
  <p>VBA Code where I continue to have the same issue.</p>
  
  <pre><code>Sub conditionalFormat()
    With Range("D5:BA9")
      .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=50"
      .FormatConditions(.FormatConditions.Count).SetFirstPriority
      With .FormatConditions(1).Font
        .Color = -16383844
        .TintAndShade = 0
      End With
      .FormatConditions(1).StopIfTrue = False
    End With
  
    With Range("D9:BA9")
      .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=40"
      With .FormatConditions(2).Font
        .Color = -16752384
        .TintAndShade = 0
      End With
      With .FormatConditions(2).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
      End With
      .FormatConditions(2).StopIfTrue = False
    End With    
  End Sub
  </code></pre>
  
  <p>Even with the SetFirstPriority on the appropriate (red text) conditional format, it just gets overwritten somehow. Am I missing something here?</p>