Initializing Multidimensional Array at Once

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
Hello, MrExcel!

One simple questions about VBA arrays.
Is there a way I can initialize all the elements inside an array at once, specifically multidimensional array?

For example, in C/C++
Code:
int c[2][5] =
{
{1,2,3,4,5},
{2,3,4,5,6},
};

What about in VBA??
Code:
Dim arr(1 To 10, 1 To 3) As Integer

All I know for initializing a VBA array is by setting value for every single element separately.
I.e:
Code:
arr(1,1) = 256
arr(1,2) = 244
arr(1,3) = 8

Is there a short way of doing this?
Otherwise, I will need 30 lines;;; which is... bad;;

Thank you in advance!
kpark
 
That actually creates a 1-dimensional of 1-dimensional arrays.
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top