title: Run macro when a cell within a certain range is changed
body: <p>I'm using this:</p>
  
  <pre><code>    Worksheet_Change(ByVal Target As Range)
  </code></pre>
  
  <p>for several purposes to run a part from my code. Now I'd like to do much the same but only run it when a value within a certain range is changed. I tried the following, but it didn't work:</p>
  
  <pre><code>    Worksheet_Change(ByVal Target As Range("C5:H5"))
  </code></pre>
  
  <p>The code checks a list of cells one by one, each cell with a value will become green, each empty cell will be coloured red. When doing this one by one you don't need to select cells, but because of the large number of cells to be coloured, I'm looping this part to prevent my code from becoming extremely long.</p>
  
  <p>By only running the code when cells within the certain range are changed, Users from my Excel sheet will still be able to edit other parts of the sheet without having the selected cell to change after every entry.</p>
  
  <pre><code>    Private Sub Worksheet_Change(ByVal Target As Range)
  
  
      Sheets("MainSheet").Range("C5").Select
      Do While ActiveCell.Offset(-1, 0) &lt;&gt; ""
          If ActiveCell.Value = "" Then
             ActiveCell.Offset(-1, 0).Interior.Color = RGB(255, 0, 0)
                  Else: ActiveCell.Offset(-1, 0).Interior.Color = RGB(0, 255, 0)
          End If
          ActiveCell.Offset(0, 1).Select
      Loop
  
  
      End Sub
  </code></pre>