Move an Array in several Sub in VBA

1

Good afternoon, how can I move an Array from one Sub to another Sub?

When I do this.

'Aqui puedo ver el dato "perro"'
Sub prueba_1()
 Dim myArray()
 myArray = Range("A1:A3").Value
 Print myArray(2,1)
 Call prueba_2
End Sub

'Aqui sale el error "No se a definido Sub o Funcion"'
Sub prueba_2()
 Print myArray(2,1)
End Sub
    
asked by Juan Alberto Loayza Cordero 20.03.2017 в 17:12
source

1 answer

1

You have to change the definition of the method prueba_2 to:

Sub prueba_2(myArray() As Variant)

To receive the array.

And in the call to that method, pass it as a parameter:

prueba_2(myArray)

Staying all together:

Sub prueba_1()
    Dim myArray()
    myArray = Range("A1:A3").Value
    Print myArray(2,1)
    prueba_2(myArray)
End Sub

Sub prueba_2(myArray() As Variant)
    Print myArray(2,1)
End Sub
    
answered by 20.03.2017 / 17:15
source