ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Syntax for multidimensional array (https://www.excelbanter.com/excel-programming/371138-syntax-multidimensional-array.html)

Arne Hegefors

Syntax for multidimensional array
 
I want to create a multidimensional array in VBA. My code is:

Dim strDataMatrix(0 To 10, 0 To 2)

Does that mean ....(rows,columns) or ....(columns,rows) ? I know how an
ordinary array works and everthing but what comes first in the
multidimensional array, the number of rows or columns? Any help very much
appreciated!

I have gooled this but with some results that do not seem coherent with
other VBA functions e.g. Offset or common mathematical notation. Therefor I
need to be sure of how it works. Thanks!



Dave Peterson

Syntax for multidimensional array
 
I think most people think rows by columns.

But it doesn't have to be either. Maybe it's heights and weights with nothing
to do with cells on a worksheet.

But if you're picking up the values from a worksheet range, then the first
dimension will be rows and the second columns.

dim strDataMatrix as variant
dim myRng as range

with activesheet
strDataMatrix = .range("a1").resize(11,3).value
end with

You started your array with 0, but this will be the same as:

dim strDataMatrix(1 to 11, 1 to 3) as variant

(when you pick up those values this way, excel will use base 1.)



Arne Hegefors wrote:

I want to create a multidimensional array in VBA. My code is:

Dim strDataMatrix(0 To 10, 0 To 2)

Does that mean ....(rows,columns) or ....(columns,rows) ? I know how an
ordinary array works and everthing but what comes first in the
multidimensional array, the number of rows or columns? Any help very much
appreciated!

I have gooled this but with some results that do not seem coherent with
other VBA functions e.g. Offset or common mathematical notation. Therefor I
need to be sure of how it works. Thanks!


--

Dave Peterson


All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com