title: How do I get the index in a VBA For Each Loop (programming with Excel)?
body: <p>I am working with EXCEL VBA to process some data and here is what I want to make:</p>
  
  <p><img src="https://i.stack.imgur.com/ep71V.png" alt="I want to develop a function that can calculate out the values in the light-green area"></p>
  
  <p>In this sheet, I want to create a function "GetDebutDate" that can automatically calculate the first date that the row has a value.</p>
  
  <p>For example, in the row of "Mark", the first time to get a value is Aug-05 with a number of "4".</p>
  
  <p>I know few about VBA and after searching around I found I can use <code>For ... Each</code> to loop in a range. But how do I get the index of the "v" in each loop? After I get that index, how do I get the value of the Date in the head row?</p>
  
  <pre><code>Function Get_Board_Count(range As range)
    For Each v In range
      ....
    Next
    Get_Board_Count = ....
  End Function
  </code></pre>