title: VBA loops to replace multible if statements
body: <p>I have an Excel worksheet with a repetitive <code>If</code> statement in VBA in a <code>Worksheet_Change</code> sub</p>
  
  <pre><code>If Range("D5") = Range("D4") Then
     Range("c5") = DateAdd("w", Range("i4"), Range("c4"))
  Else
     Range("c5") = Range(c2")
  End If    
  If Range("D6") = Range("D5") Then
     Range("c6") = DateAdd("w", Range("i5"), Range("c5"))
  Else
     Range("c6") = Range(c2")
  End If
  </code></pre>
  
  <p>it will repeat from <code>D5</code> to <code>D150</code> my question is can I rewrite this in a loop instead of repeating the if statement 145 times?</p>
  
  <p>Im not to good when it comes to loops</p>
  
  <p>Thanks</p>