title: Nested For Loop in Excel VBA
body: <p>The following code is working for only when <code>c = 2</code> ,however I want it to work for other values as well. Below is the Excel table on which I want to run it. </p>
  
  <pre><code>Date    PickupCost  StorageCost DeliveryCost
  1/1/2017    140       35          0
  1/8/2017    80        20          0
  1/10/2017   0          0         149
  1/30/2017   35         8          0
  </code></pre>
  
  <p>I want to fill data of each date missing but only the value at column 3 (<code>StorageCost</code>) needs to be same in other missing date values as previous day's <code>StorageCost</code> value. </p>
  
  <pre><code>Dim j, p, w, c As Long
  Dim date1, date2 As Date
  j = Cells(Rows.Count, 1).End(xlUp).Row
  w = 2
  For c = w To j
     date1 = Range("A" &amp; w).Value
     date2 = Range("A" &amp; (w + 1)).Value
     p = DateDiff("d", date1, date2)
     For w = 2 To p
         Range("A" &amp; (c + 1)).EntireRow.Insert
         ActiveSheet.Cells(c + 1, 1).Value = (ActiveSheet.Cells(c, 1).Value) + 1
         ActiveSheet.Cells(c + 1, 2).Value = 0
         ActiveSheet.Cells(c + 1, 3).Value = ActiveSheet.Cells(c, 3).Value
         ActiveSheet.Cells(c + 1, 4).Value = 0
         c = c + 1
     Next w
     w = w + 1
     ActiveSheet.Range("A1").Select
     j = Cells(Rows.Count, 1).End(xlUp).Row
  Next c
  </code></pre>