title: Excel VBA: Color range based on cell value
body: <p>I am writing code so that when the value of a cell has a certain value it highlights a range for that row (columns G-O, but not the entire row). The code below is recognizing the values of "c" correctly but coloring random rows. For example, when row 2 (O2) has a value under 40, it colors row 4. Please help!</p>
  
  <pre><code>Sub color()
  
      Dim lastrow As Long
      Dim c As Variant
  
      lastrow = Range("o" &amp; Rows.Count).End(xlUp).Row
      For Each c In Range("O1:O" &amp; lastrow)
          If c.Value &lt; 40 Then
               ' MsgBox (c)
               Range(Cells(c, 7), Cells(c, 15)).Interior.ColorIndex = 7 
          End If
      Next c
  
  End Sub
  </code></pre>