XL: Row and Column Range Converted to Two-Dimensional ArrayLast reviewed: September 2, 1997Article ID: Q115513 |
The information in this article applies to:
SUMMARYPage 127 of the Microsoft Excel 5.0 "Visual Basic User's Guide," states that a Microsoft Excel horizontal or vertical array is converted to a one- dimensional Visual Basic array. This information is not entirely correct. When you define a variable in a procedure based on a row or a column of cells on a worksheet, the variable is converted to a two- dimensional array. Note that the examples used on page 127 of the Microsoft Excel 5.0 "Visual Basic User's Guide" ARE correct. A horizontal or vertical array such as {"Apples",7,19} or {"Apples";7;19} is converted to a one- dimensional Visual Basic array.
MORE INFORMATIONIn Microsoft Excel, if you dimension a row or column of cells on a worksheet as an array in a Visual Basic module, and you return a value in the array as an element of a one-dimensional array, you receive the following error message:
Run-time error '9': Subscript out of rangeTo avoid receiving the error message above when you return a value from a variable that has been defined as a worksheet row or column, return the value as an element of a two-dimensional array as in the following example. Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.
Sample Visual Basic Macro
Sub ArrayExample() ' Dimension variable Column_Variable as Variant type Dim Column_Variable as Variant ' Assign variable Column_Variable to named range Vert ' Vert contains the vertical range A1:A3 Column_Variable = ThisWorkbook.Sheets("Sheet1").Range("Vert") ' Return value in A2, element in second row, first column in array MsgBox Column_Variable(2, 1) End Sub REFERENCESFor more information about Creating Arrays, click the Search button in the Visual Basic Reference help and type:
arrays |
Additional query words: 1.00 5.00 7.00 8.00 97 err msg docerr
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |