title: Excel VBA sort array function
body: <p>I've written the function displayed below. It works when I use it in the Sub. This is the first time that I'm trying to write a function. I know this is a noob question however I can't seem to get the function to run. It's probably something about not calling the function correctly or maybe not defining the variables in the function header correctly</p>
  
  <p>Can anyone please point me in the right direction.</p>
  
  <pre><code>Function SortArray(ArrayToSort As String)
      Dim x As Long, y As Long
      Dim TempTxt1 As String
      Dim TempTxt2 As String
  
      For x = LBound(ArrayToSort) To UBound(ArrayToSort)
          For y = x To UBound(ArrayToSort)
              If UCase(ArrayToSort(y)) &lt; UCase(ArrayToSort(x)) Then
                  TempTxt1 = ArrayToSort(x)
                  TempTxt2 = ArrayToSort(y)
                  ArrayToSort(x) = TempTxt2
                  ArrayToSort(y) = TempTxt1
              End If
          Next y
      Next x
  End Function
  
  
  Sub CreateUniquesList()
      Dim References() As String
      ...
      SortArray (References)
      ...
  End Sub
  </code></pre>