title: Excel VBA: On Error Goto statement not working inside For-Loop
body: <p>I'm trying to cycle through a table in excel. The first three columns of this table have text headings, the rest of them have dates as headings. I want to assign those dates, sequentially, to a Date-type variable, and then perform some operations based on the date</p>
  
  <p>To do this I am using a foreach loop on myTable.ListColumns. Since the first three columns do not have date headers, I have tried to set the loop up so that, if there is an error assigning the header string to the date-type variable, the loop goes straight to the next column</p>
  
  <p>This seems to work for the first column. However, when the second column's header is 'assigned' to the date-type variable, the macro encounters an error even though it is within an error-handling block</p>
  
  <pre><code>Dim myCol As ListColumn
  For Each myCol In myTable.ListColumns
      On Error GoTo NextCol
  
      Dim myDate As Date
      myDate = CDate(myCol.Name)
  
      On Error GoTo 0
  
      'MORE CODE HERE
  
  NextCol:
      On Error GoTo 0
  Next myCol
  </code></pre>
  
  <p>To reiterate, the error is thrown on the second round of the loop, at the statement</p>
  
  <pre><code>myDate = CDate(myCol.Name)
  </code></pre>
  
  <p>Can anyone explain why the On Error statement stops working?</p>