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

arrays array variables

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

Arrays / Array Variables

ResolvedVersion 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:

Turn Function tooltips on and off

Excel 2002 (XP) and Excel 2003 have the Function tooltips facility. When you type in a function name followed by a bracket, for example, =IF(, a yellow box appears beside the function name and lists the function's arguments. This is very useful when you can't quite remember the order of a function's arguments or what the arguments actually are!

However, Function tooltips can become annoying. To turn them off, choose Tools|Options. and select the General tab. Then, untick the Function tooltips box and choose OK.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.16 secs.