title: Return custom objects Excel VBA
body: <p>I have dificulties figuring how a function can return an object in Excel VBA.</p>
  
  <p>For example, in Java, I am used to write it like this:</p>
  
  <pre><code>Private ArrayList&lt;&gt; getARandomArrayList() {
      //... My code
      return anArrayList;
  }
  </code></pre>
  
  <p>This method should return an arrayList that I can use. </p>
  
  <p>If I do this in Excel, I believe it is supposed to look like this:</p>
  
  <pre><code>Function getARandomArrayList() As System.Collections.ArrayList
      '... My code
      getARandomArrayList = anArrayList
  End Function
  </code></pre>
  
  <p>When I try to use this kind of function, I get a "Compile error: User-defined type not defined" error window. If I use variables type like Double or String, I have no problem. It is only with objects that I get errors. </p>