title: Passing an empty/optional argument to a VBA function
body: <p>I was under the impression that if a function has been defined with some <em>Optional</em> arguments then you can pass <code>Nothing</code> and it will be treated in the same way as "not passing anything at all".</p>
  
  <p>However, I can't make that work. Here's a code snippet that runs perfectly well if all the <em>"fds..."</em> variables are not empty but throws <em>"Invalid procedure call or argument"</em> if any arguments are <code>Nothing</code>:</p>
  
  <pre><code>Dim fdsSortOrders(2) As Variant
  Dim fdsKey1 As Variant
  Dim fdsKey2 As Variant
  Dim fdsKey3 As Variant
  
  ' ...skipped...
  
  Call loFinalReport.DataBodyRange.Sort( _
      Header:=xlYes, _
      Key1:=fdsKey1, Order1:=fdsSortOrders(0), _
      Key2:=fdsKey2, Order2:=fdsSortOrders(1), _
      Key3:=fdsKey3, Order3:=fdsSortOrders(2) _
  )
  </code></pre>
  
  <p>Is there a way to pass an <em>Optional</em> argument or shall I make ugly copy-paste code ("<code>if fdskey2 is nothing and fdskey3 is Nothing Then SortUsingKey1Only</code>)?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This will work since Key2/Key3 and Order2/Order3 are Optional, but I don't want to write three versions of procedure call:</p>
  
  <pre><code>Call loFinalReport.DataBodyRange.Sort( _
      Header:=xlYes, _
      Key1:=fdsKey1, Order1:=fdsSortOrders(0) _
  )
  </code></pre>