I need to pass distinct arrays to a routine that sorts its elements and receives other treatments, and then I want it to return those sorted and treated values to the original array ; for example, I passed out-of-order values and some fractionated into the routine through an array, first the fractional values are rounded and then sorted, then returned to the array that "fed" the routine in this way (without decimals and ordered).
First the data is taken from a spreadsheet in Excel and fill in the matrices that I will treat. This data can not be changed because it is typed data and must remain in the order and as it was typed, however, I need to resolve these cases only by VBA .
The idea is to have a routine that treats the matrix passed to it, which works, but that the values of the original matrix, receive back the treated values; this I could not do or find how to do.
I looked it up for VBA , but what I found only refers to using these array values within the routine , but not returning the result to the original array .
The example below has been taken from the link :
Understanding Parameter Arrays
The example works to receive and manipulate these values, however I need to have the results returned to the original array which in my case are dimensioned variables, not just data as this example shows.
Can you do this in VBA / Excel?
The following example shows how you can define a procedure with an array of parameters.
Sub AnyNumberArgs(strName As String, ParamArray intScores() As Variant)
Dim intI As Integer
Debug.Print strName; " Scores"
' Use UBound function to determine upper limit of array.
For intI = 0 To UBound(intScores())
Debug.Print " "; intScores(intI)
Next intI
End Sub
The following examples show how you can call this procedure.
AnyNumberArgs "Jamie", 10, 26, 32, 15, 22, 24, 16
AnyNumberArgs "Kelly", "High", "Low", "Average", "High"
Basically the tests I did had this format, however I made numerous attempts to change the way the array is used, calling the function, changing the type of variable declared in the function, and so on. How the basics did not work. I did not have the complete code, because I tried to test first before doing the routine, since I had never done this before: I used the function because the idea is that it "returns" with the data processed and I did not make public statements, it would work this way. So the code below shows the structure of the idea of how to try to solve the problem:
Private Sub CommandButton1_Click()
...
...
MatrizA() = TrataDepoisRetornaMatriz( MatrizA(), QtdeDeItensDaMatrizA )
MatrizB() = TrataDepoisRetornaMatriz( MatrizB(), QtdeDeItensDaMatrizB )
MatrizC() = TrataDepoisRetornaMatriz( MatrizC(), QtdeDeItensDaMatrizC )
...
...
...
End Sub
Private Function TrataDepoisRetornaMatriz( _
ParamArray Matriz() As Variant, _
Byval QtdeDeItensDaMatriz As Integer) _
As Variant
...
...
...
TrataDepoisRetornaMatriz = Matriz()
End Function