arrays array variables

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Arrays / Array Variables

Arrays / Array Variables

resolvedResolved · Low Priority · Version 2003

Daniell has attended:
Excel VBA Intro Intermediate course

Arrays / Array Variables

What is the best way to write arrays / and using array variables?

Edited on Fri 13 Jun 2008, 16:59

RE: Arrays / Array Variables

Hi Daniel

Arrays are useful when you must store a number of values of the same type, but you do not know how many, or you do not want to create individual variables to store them all.

The indexing in an array by default begins at 0 so declaring an array as

Dim SalesYear(5) as Integer

will allow you to store 6 years (0 t0 5) as the 5 sets the upper limit of the array, not the number of memory spaces

Then in the code SalesYear(3) will return the value stored in that section of the array. This is refered to as a Static array

But the best way to write Arrays is to create Dynamic arrays.

In this case you define the array but not the size. This can be defined later as seen below:

Dim SalesYear as Integer

ReDim SalesYear (1 To 20)


This sets an Array with space for 20 integers

NB You can change the size of a dynamic array, but not the data type

Hope this helps

Carlos

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Enter formulae into multiple cells

If a formula is to be used in a series of cells, select the cells first. Now type in your formula and hold the Ctrl key while you press Enter. This enters the formula in each selected cell.

Just be careful with your absolute and relative cell references.

View all Excel hints and tips


Server loaded in 0.07 secs.