Reliable Spreadsheet Solutions - Call Now 281-379-2000 Microsoft Excel - Visual Basic for Applications Consultant   Reliable Spreadsheet Solutions - Call Now 281-379-2000 !
PROFESSIONAL SOFTWARE DEVELOPMENT
Reliable Excel VBA Solutions !
 
Microsoft Office : Excel - Visual Basic for Applications [ VBA ] Software 

Beyond Technology

Insight for Microsoft Excel POWER-Users
Spreadsheet Power-User Tips
  Enable ease and consistency of data entry with a dropdown list of possible entries for a range  dropdown list in cell
  Designing an array formula that functions similar to a VLOOKUP function with multiple criteria and returns a text entry  mult-criteria text lookup
  How Excel workbooks become bloated and what can be done about it  spreadsheet bloat
  Spreadsheet Power-User Tips  more ...
Getting to Know Microsoft Visual Basic for Applications
  Decision Structure that conditionally executes the embedded code  if...then[...else]
  If you are new to VBA and trying to get a handle on programming, this is a MUST READ article for you!  what are variables ?
  Discover a special, more flexible variety of arrays  dynamic arrays
  Getting to Know Microsoft Visual Basic for Applications  more ...
Microsoft Excel Advanced VBA - Just for Geeks
  MUST SEE!  A named range that expands and contracts automatically based on the number of items in the source data table  dynamic named ranges
  MUST SEE! How to identify the last used row in an Excel worksheet  finding real last cell
  Creating charts that adapt as the size of the source data range varies  charting dynamic data
  Microsoft Excel Advanced VBA - Just for Geeks  more ...
Excel Spreadsheet Tools and Tutorials
  Mortgage & Auto Loan Payment Calculator » Amortization with Excel Spreadsheets  amortization guide
  Breakeven Analysis with Excel Spreadsheets Tutorial  breakeven analysis
  Standard Deviation in Excel Spreadsheets Tutorial  standard deviation
  Weighted Average in Excel Spreadsheets Tutorial  weighted average


Microsoft Excel VBA Custom Application Development
  Microsoft Excel VBA Custom Application Development  excel vba customization
  Microsoft Excel VBA Professional Development Experience  professional experience
  Microsoft Excel VBA Custom Application Development  project request form
Microsoft Excel VBA Solutions : Real-World Project Profiles
  How deep is your data?  engineering analysis
  Financial reporting can be a challenging endeavor.  financial reporting
  To anticipate customers needs is to be rewarded with their business.  sales forecasting
  Are time-hungry paperwork tasks building up on you?  automated billing
  An Engineer-in-a-Box  engineering design
  Partial List of Beyond Technology Clients - Past & Present  clients - past & present


Reliable Spreadsheet Solutions - Call Now 281-379-2000 !
  Visitors' Comments  gratuitous kudos
  Add to Favorites 
  Reliable Spreadsheet Solutions - Call Now 281-379-2000 !  e-mail contact

20831 Rosehill Church Rd
Tomball, Texas 77377


What are Arrays?

Rodney POWELL
Microsoft MVP - Excel
need a developer for
your excel project ?
go here
An array is a group of variables, usually of the same data type, arranged contiguously in memory. These variables share a common name. Each variable within an array is called an element and you use a number (an index) to tell them apart. An index simply means an identifying number.

In VBA there are two categories of arrays:
  • fixed-size array - always remains the same size

  • dynamic array - size can change at run-time
For now, we'll focus on the fixed-size array. You declare a fixed-size array just as you would a regular variable, except that you also need to specify the number of elements in the array. This is done in parentheses following the name of the array as you declare it. For example:

   Dim MyOneDimensionalArray(10)

or

   Dim MyTwoDimensionalArray(10,10)

In these examples, only the upper bound of the arrays have been specified. The default lower bound is 0 (for a zero-based array). However you can change the default lower bound so the index for the first element will be 1 by placing an Option Base 1 statement in the General Declarations section.

Another way to specify a lower bound is to provide it explicitly using the To keyword. Here is an example of explicitly declaring the upper and lower bounds for a 50 element array beginning after an index of 100:

	Dim MyArray(101 to 150)

A one-dimensional array is useful for storing a series of values. It may help to think of it as a list. For example, you may declare an array of 7 string variables so that each element corresponds to the name of a different day of the week.

Sub OneDimensionalArray()
   Dim a&, aDayOfWeek$(7)

'  Initialize elements of one-dimensional array

   aDayOfWeek$(1) = "Monday"
   aDayOfWeek$(2) = "Tuesday"
   aDayOfWeek$(3) = "Wednesday"
   aDayOfWeek$(4) = "Thursday"
   aDayOfWeek$(5) = "Friday"
   aDayOfWeek$(6) = "Saturday"
   aDayOfWeek$(7) = "Sunday"

'  Loop through the array and display each of
'  it's elements

   For a& = 1 To 7
      MsgBox aDayOfWeek$(a&)
   Next a&

End Sub

A two-dimensional array is similar to a table in a database. One dimension represents the number of rows in the table, while the other specifies how many columns (fields) you are defining. Therefore, each element in a two-dimensional array can be referred to by its X and Y coordinates. You can efficiently process a multidimensional array by using nested loops.

Sub TwoDimensionalArray()
   Dim c&, r&, Counter&, aMatrix&(3, 3)


   For c& = 1 To 3
      For r& = 1 To 3

      '  Increment a counter variable

         Counter& = Counter& + 1

      '  Populate an element of the array
      '  with counter value

         aMatrix&(r&, c&) = Counter&
      Next r&
   Next c&

End Sub

A three-dimensional array is like a cube. Most arrays are only one- or two-dimensional. Although VBA allows you to create arrays of up to 60 dimensions, a need for more than a three-dimensional array would be rare. And, because VBA allocates memory space for every possible element in a declared array, regardless of whether or not you actually store a value in that element, avoid declaring an array any larger than is necessary. Always remain mindful of the size of your arrays, since they can have significant memory requirements.

Arrays are so powerful, as they makes it so much easier to work with groups of variables. This enables you to develop shorter and simpler procedures, because you can use loops that deal efficiently with your variables.

Reliable Spreadsheet Solutions - Call Now 281-379-2000 !

Know an even better way? Let me know.

Beyond Technology Custom Application Development
  home Microsoft Excel VBA Custom Application Development  professional consulting Insight for Microsoft Excel POWER-Users  developer tips Visitors Comments  visitor kudos Beyond Technology - Microsoft Solution Provider  e-mail  

Your suggestions and comments are greatly appreciated. Please keep them coming.

Mail to:   rodney@beyondtechnology.com

All terms, product designs, and company names used in this site may be trademarks or registered trademarks of their respective owners, and are hereby acknowledged. © 1996 - 2010 Beyond Technology. All rights reserved.