title: Excel vba: Reassign collection member
body: <p>I have a <code>Collection</code> that stores <code>Date</code> objects. I want to check if a month of a date object is different from 1 and if so, set it to 1.  </p>
  
  <pre><code>Sub displayColl()
      Dim globals As Object
      Set globals = getGlobalVariables()
  
      Dim dates As Collection
      Set dates = getResultDates(globals("MIN_DATE"), globals("MAX_DATE"), False)
  
      Dim i As Integer
      For i = 1 To dates.Count
           Debug.Print dates(i)
      Next
  
      Debug.Print "After"
  
      For i = 1 To dates.Count
          Debug.Print dates(i)
          dates(i) = DateSerial(year(dates(i)), 1, Day(dates(i)))
      Next
  End Sub
  </code></pre>
  
  <p>However, this code doesn't work - I get <code>Object requered error</code>. Why is that? What is the right way to do it?</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <ul>
  <li><p><code>getResultDates</code> function isn't important. It simply returns a <code>Collection</code> of <code>Dates</code>.</p></li>
  <li><p>The same goes for <code>getGlobalVariables</code> - it returns a dictionary with information from user, including minimum and maximum dates a user wrote. </p></li>
  <li><p>The error occurs on line <code>Set dates(i) = DateSerial(year(dates(i)), 1, Day(dates(i)))</code>.</p></li>
  <li><p>Removing <code>Set</code> doesn't accomplish anything.</p></li>
  <li><p>I am sure the <code>dates</code> <code>Collection</code> contains dates. </p></li>
  </ul>
  
  <p>The debug output:</p>
  
  <pre><code>01.01.2014 
  01.02.2014 
  01.03.2014 
  01.04.2014 
  01.05.2014 
  01.06.2014 
  01.07.2014 
  01.08.2014 
  01.09.2014 
  01.10.2014 
  01.11.2014 
  01.12.2014 
  01.01.2015 
  01.02.2015 
  01.03.2015 
  01.04.2015 
  01.05.2015 
  01.06.2015 
  01.07.2015 
  01.08.2015 
  01.09.2015 
  01.10.2015 
  01.11.2015 
  01.12.2015 
  01.01.2016 
  01.02.2016 
  01.03.2016 
  01.04.2016 
  01.05.2016 
  01.06.2016 
  01.07.2016 
  01.08.2016 
  01.09.2016 
  01.10.2016 
  01.11.2016 
  01.12.2016 
  01.01.2017 
  After
  01.01.2014 
  </code></pre>