centinela90
12-24-2015, 12:36 PM
Hi, my name is Arturo. Thanks for reading.
I am a novice using VBA in Excel. I have this code that is useful:
Sub Arreglo()
Dim Paises(1 To 5) As String
Paises(1) = Range("C45").Value
Paises(2) = Range("C46").Value
Paises(3) = Range("C47").Value
Paises(4) = Range("C48").Value
Paises(5) = Range("C49").Value
For i = 1 To 5
MsgBox Paises(i)
Next i
End Sub
It shows a message box with the value of the cells specified. For learning reasons, I wanted to test making the code shorter by using a for to capture the cells value in the array instead of typing each one.
So I changed it to this:
Sub Arreglo()
Dim Paises(1 To 5) As String
'What I changed:
For j = 1 To 5
Paises(j) = Cells(3, 44+j).Value
Next j
For i = 1 To 5
MsgBox Paises(i)
Next i
End Sub
When I run the macro, an Message Box appears but with blank content. What am I doing wrong?
Thank you!
I am a novice using VBA in Excel. I have this code that is useful:
Sub Arreglo()
Dim Paises(1 To 5) As String
Paises(1) = Range("C45").Value
Paises(2) = Range("C46").Value
Paises(3) = Range("C47").Value
Paises(4) = Range("C48").Value
Paises(5) = Range("C49").Value
For i = 1 To 5
MsgBox Paises(i)
Next i
End Sub
It shows a message box with the value of the cells specified. For learning reasons, I wanted to test making the code shorter by using a for to capture the cells value in the array instead of typing each one.
So I changed it to this:
Sub Arreglo()
Dim Paises(1 To 5) As String
'What I changed:
For j = 1 To 5
Paises(j) = Cells(3, 44+j).Value
Next j
For i = 1 To 5
MsgBox Paises(i)
Next i
End Sub
When I run the macro, an Message Box appears but with blank content. What am I doing wrong?
Thank you!