title: Loop through columns with conditional if in Excel
body: <p>I'm needing to write an excel script to fill in some data.  Essentially what needs to happen is the script should loop through each record and when it hits a "1" it should follow each cell with another "1" until it hits the next "1".  My goal is to fill in the gaps between 1s with more 1s.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>Dim i, j As Integer
  
  finalrow = Cells(665, 1).End(x1up).Row
  finalcol = Cells(1, 10).End(x1toleft).Column
  
  For i = 1 To finalrow
      If Cells(i, j).Value = "0" Then
          For j = 1 To finalcol
              Next j
      Else
          For j = 1 To finalcol
              Next j
              Cells(i, j).Value = "1"
      End If
  Next i
  </code></pre>
  
  <p>I keep getting an error when this is ran.</p>
  
  <p>My data is structured like this:</p>
  
  <pre><code>0   0   1   0   0   0   1   0   0   0
  1   0   0   1   0   0   0   0   0   0
  0   0   0   1   0   0   1   0   0   0
  0   0   0   1   1   0   0   0   0   0
  </code></pre>
  
  <p>Any help or advise is much appreciated.</p>
  
  <p>Thanks.</p>