lucavilla
asked on
oneliner 2D array creation in Excel VBA?
How can I declare a 2D array specifying all the values with a single line of code in Excel VBA?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Or if your data is in a range, say A1:C27 on your worksheet:
Dim vData As Variant
vData = Range("A1:C27").Value
Or you can use the Array function:
vData = Array(Array(1, 2, 3), Array(4, 5, 6), Array(5, 6, 7))
but this is not as concise as Rory's, and the elements have to be accessed by the less obvious
vData(i)(j)
rather than
vData(i, j)
as in the other examples
ASKER
I asked here because the following 2D array declaration returns a "Run-time error '13': Type Mismatch error"
aNomeFogli = [{"Istruttoria","Note" & Chr(10) & "(Opzionale)"; "Stipula","T"; "Post Stipula","L"}]
I now discovered that the cause is that Chr(10).
How could I avoid the error keeping it and keeping the declaration of minimalist lenght?
aNomeFogli = [{"Istruttoria","Note" & Chr(10) & "(Opzionale)"; "Stipula","T"; "Post Stipula","L"}]
I now discovered that the cause is that Chr(10).
How could I avoid the error keeping it and keeping the declaration of minimalist lenght?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
you have to loop through the array entering the value into each value:
Such as below...
Open in new window