title: VBA Sorting Comma Separated Array - Not sorting
body: <p>I'm trying to sort this array by the second number in the CSV. The result should be &quot;1,7&quot; first.</p>
  <p>I have it split by comma in the for loop, so it should be comparing 0 to 7 and listing that first.</p>
  <p>I'm not very talented with VBA. Does anyone know what I'm doing wrong here?</p>
  <pre><code>Public Function SortArray(ByRef arr() As Variant) As Variant
  
  Dim temp As String, temparr As Variant
  Dim i As Long, j As Long
  Dim tempspi As String, tempspj As String
  
  ReDim arr(5)
  
  arr = Array(&quot;0,0&quot;, &quot;1,7&quot;, &quot;2,0&quot;, &quot;3,1&quot;, &quot;4,3&quot;, &quot;5,1&quot;)
  
  For i = LBound(arr) To UBound(arr) - 1
  tempspi = Split(arr(i), &quot;,&quot;)(1)
      For j = i + 1 To UBound(arr)
      tempspj = Split(arr(j), &quot;,&quot;)(1)
          If CLng(tempspi) &gt; CLng(tempspj) Then
              temp = arr(i)
              arr(i) = arr(j)
              arr(j) = temp
          End If
      Next j
  Next i
  
  For Each Item In arr
      Debug.Print Item
  Next
  
  SortArray = arr
  
  
  
  End Function
  </code></pre>
  <p><strong>DEBUG RESULT:</strong></p>
  <pre><code>0,0
  5,1
  4,3
  3,1
  2,0
  1,7
  </code></pre>