title: excel custom function for a loop
body: <p>I'm a newbie to excel VB so I hope some one can help me with this:
  I'm trying to calculate the row number of the first cell which doesn't have the value zero in a column(eg:if it's 0 0 0 1 should give me 4) but have a hard time in making it display on the worksheet,
  Here is my code- </p>
  
  <pre><code>Function Module1(y As Integer)
  Dim x As Integer
  x = 1
  Dim a As Integer
  a = 0
  Do While x &lt; 100 Or a &lt;&gt; 0
      If Cells(x, y).Value = 1 Then
      a = x
  
  x = x + 1
  Loop
  Cells(y, 101).Value = a
  End Function
  </code></pre>
  
  <p>y is the column number I want to get this function and there are 100 columns.</p>