title: Converting VBA Collection to Array
body: <p>I am trying to create an array with all the worksheet names in my workbook that have the word 'Template' in it. I thought the easiest way to do this would be to create a collection first and then convert it to an array but I am having trouble. Right now the error I am getting is on the </p>
  
  <pre><code>collectionToArray (col)
  </code></pre>
  
  <p>line. I am receiving an </p>
  
  <blockquote>
    <p>Argument Not Optional error</p>
  </blockquote>
  
  <p>Pretty stuck, any help is super appreciated. Thanks!!</p>
  
  <pre><code>Public col As New Collection
  Public Sub Test()
  For Each ws In ThisWorkbook.Worksheets
      If InStr(ws.Name, "Template") &lt;&gt; 0 Then
          col.Add ws.Name
      End If
  Next ws
  
  collectionToArray (col)
  End Sub
  
  Function collectionToArray(c As Collection) As Variant()
      Dim a() As Variant: ReDim a(0 To c.Count - 1)
      Dim i As Integer
      For i = 1 To c.Count
          a(i - 1) = c.Item(i)
      Next
      collectionToArray = a
  End Function
  </code></pre>