Array Declaration Questions

chuckjitsu

New Member
Joined
Apr 24, 2015
Messages
48
Office Version
  1. 365
  2. 2016
Let's say you see code like this:
VBA Code:
Dim myArray (1 to 5) as Byte

I'm assuming this means that by declaring the array as the byte data type, all the data elements in the array are of the declared variety (0 to 255)? Is that correct?

Now, let's say you had another array you were using to store myArray- an array of arrays if you will. We'll call this the second array myArray2. Can myArray2 be declared as something other than the Variant type? What are the declaration rules for an array that stores other arrays?

Thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Yes, you are correct. When you declare an array of type Byte, it means that each element of the array will hold a value in the range of 0 to 255.

Regarding the second array (myArray2), it can indeed be declared as a different data type other than Variant, as long as it is capable of storing the values of the first array (myArray).

In VBA, you can declare the second array as an array of arrays, by using nested square brackets []. For example:

Dim myArray2 (1 to 5, 1 to 5) as Byte

This declares myArray2 as a two-dimensional array, with 5 elements in each of the 5 dimensions.

Keep in mind that each element of the inner array (myArray) must have the same data type, in this case, Byte, so that the values of myArray can be stored in myArray2.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,425
Messages
6,124,826
Members
449,190
Latest member
rscraig11

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