title: How to swap an integer array's value and index in vb macro
body: <p>How to swap an integer array's value and index in vb macro</p>
  
  <pre><code>i(0 to 5) = {3,4,1,5,0,2}
  To
  i(0 to 5) = {4,2,5,0,1,3}
  </code></pre>
  
  <p>editing...</p>
  
  <p>Thankyou @Tim and @Cody</p>
  
  <p>The following function is what i have got, but looking for better and more efficent ways to do it with/without the array l_aiOldIndexSwap</p>
  
  <pre><code>    Public Function SortValuePairs(ByRef l_aiValues() As Integer) As Integer()
       Dim l_aiOldIndexSwap() As Integer
       ReDim l_aiOldIndexSwap(LBound(l_aiValues) To UBound(l_aiValues))
       For i = LBound(l_aiValues) To UBound(l_aiValues)
        l_aiOldIndexSwap(l_aiValues(i)) = i
       Next
       SortValuePairs = l_aiOldIndexSwap
      End Function
  </code></pre>