Hi Remy.
An Array is a group of things called elements.
You can create an array in a similar way to what you are trying using a loop or you can populate an array in one go like so:
Sub ShowArrayBuilding()
Dim MyArray as variant '<-- need to do this to populate in one go
MyArray = Array("Hello","World","123")
end sub
This has now created an array for us with 3 elements, we can prove this by adding the following lines before end sub
For X = lbound(MyArray) to ubound(MyArray)
msgbox(MyArray)
Next
We would also need to dim the variable X as a long up the top of the sub.
Now, an array can also be populated from a range like so:
Sub ShowArrayBuilding()
Dim MyArray As Variant '<-- need to do this to populate in one go
MyArray = Range("M2:M4")
End Sub
And you can also refer to the elements of an array as a collection using for each like so:
Sub ShowArrayBuilding()
Dim MyText As Variant, MyArray As Variant '<-- need to do this to populate in one go
MyArray = Range("M2:M4")
For Each MyText In MyArray
MsgBox MyText
Next
End Sub
Last but by no means least, I think you should check out multi dimension arrays, these things are awesome.
You can have arrays instead of MyArray(1) MyAray(2) MyArray(3) etc you can have many dimension like MyArray(1,1) MyArray(1,2) MyArray(1,3) MyArray(2,1) MyArray(2,2) etc
You are not limited to 2 dimensions either, these things can get massive. So how would that be useful?
Consider you have a bunch of CD's
On each CD you have a bunch of tracks
You can refer to these tracks using a collective 2 dimension array.
Now expand your thoughts to a planet which has many oceans which has many ships which carry many shipping containers which have many boxes which contain many items
You are now at 6 dimension which the ability to pinpoint 1 individual item through simply knowing 6 location digits.
I hope this has helped you. Post back if you have more questions