return an entire row of a multidimensional array in VBA to a one dimensional array

surya teja3 picture surya teja3 · Jan 5, 2013 · Viewed 83.8k times · Source

Is there any way to return the value of an entire row of a multidimensional array to a one dimensional array In VBA?

Something like, arr_1dim = arr_2dim(3,:) is a matlab expression for assigning the row 3 of arr_2dim array to arr_1dim in one single stretch.

Is there any similar less expensive method in Excel VBA?

Answer

rxex picture rxex · May 27, 2016

There is a simple way to get a column or a row of a two-dimensional array. Assign a zero to column to get the row, or assign a zero to row to get the column, thus:

Application.WorksheetFunction.Index(array, 0, columnyouwant) /* or */
Application.WorksheetFunction.Index(array, rowyouwant, 0)

See here: How do I slice an array in Excel VBA?