VBA Array Constants: Use `Array()`, Not Excel Braces
In VBA, create an in-code array of values with the Array() function, such as Array(1, 2, 3); Excel’s brace expression ={1,2,3} is a worksheet array constant, not VBA syntax. VBA also lets you declare typed fixed-size or dynamic arrays with Dim and ReDim. The right approach depends on whether you are writing code in the Visual Basic Editor or entering a formula into an Excel worksheet.
VBA Arrays and Excel Array Constants Are Different
Use Array() and array declarations for VBA code; use {...} only inside Excel worksheet formulas.
An Excel array constant is a literal group of values in a worksheet formula. For example, this formula places five values across a row:
={1,2,3,4,5}
A VBA array is a variable that holds multiple values in memory. You can initialize one with the VBA Array() function:
Array("Queued", "Running", "Finished")
Do not paste an Excel brace constant directly into VBA code. This is Excel formula syntax, not a VBA array literal:
={1,2,3}
VBA also does not support a true constant array declared with Const. An array created with Array() can be treated as read-only by convention, but VBA does not enforce immutability for it.
How to Create and Use a VBA Array
Choose the form that matches where the values will be used.
| You Need To Do | Use | Example |
|---|---|---|
| Store a short list directly in VBA code | Array() |
statuses = Array("New", "Done") |
| Store a fixed number of values of one type | Typed Dim array |
Dim totals(1 To 12) As Double |
| Add values while a macro runs | Dynamic array with ReDim |
ReDim names(0 To count - 1) |
| Enter literal values in worksheet cells | Excel array constant | ={1,2,3} |
| Write an Excel array formula from VBA | Range.FormulaArray |
Formula text containing {...} |
Step 1: Set the Array Index Convention
Put Option Explicit at the top of every VBA module so VBA requires variable declarations. If you want arrays with unspecified lower bounds to start at 1, put Option Base 1 beneath it before declaring or looping through arrays.
Option Explicit
Option Base 1
Without Option Base 1, VBA array indexes begin at 0 when you do not explicitly provide a lower bound. In shared code, explicit bounds such as 0 To 4 or 1 To 5 are clearer because they do not depend on the module setting.
Step 2: Initialize a List With Array()
Declare the receiving variable as Variant, then assign the result of Array(). This is the most direct substitute for what many developers mean when they search for a VBA “array constant.”
Dim statuses As Variant
statuses = Array("Queued", "Running", "Finished")
The values can be numbers, strings, dates, or mixed types. A mixed list is convenient for small lookup lists, but typed arrays are usually a better choice for large collections of one data type.
Step 3: Read Every Item Safely
Use LBound and UBound instead of assuming that the first item is index 0 or 1. This makes the loop work regardless of the module’s index base or explicitly declared bounds.
Dim statuses As Variant
Dim i As Long
statuses = Array("Queued", "Running", "Finished")
For i = LBound(statuses) To UBound(statuses)
Debug.Print statuses(i)
Next i
Run the procedure, then inspect the Immediate window in the Visual Basic Editor to confirm that each value appears once and in order.
Declare Fixed and Dynamic VBA Arrays
The Array() function is ideal for a compact initialized list. Use a declared array when you need a known type, multiple dimensions, or a size that changes at runtime. Microsoft’s VBA array declaration guidance distinguishes fixed-size arrays from dynamic arrays.
Fixed-Size Typed Arrays
A fixed-size array has its bounds in the declaration. This declaration creates a two-dimensional Integer array:
Dim MyArray(10, 10) As Integer
With the default zero-based indexing, Dim MyArray(10, 10) As Integer creates 11 rows and 11 columns: indexes 0 through 10 in each dimension. The first dimension is the row index, and the second is the column index.
Use explicit lower and upper bounds when the intended indexes matter:
Dim monthlyTotals(1 To 12) As Double
A declaration bound must be a constant expression. A variable upper bound such as Dim names(count) As String can cause a “constant expression required” compile error.
Dynamic Arrays That Grow at Runtime
Declare a dynamic array with empty parentheses, then allocate it with ReDim once you know its required size.
Dim names() As String
Dim count As Long
count = 3
ReDim names(0 To count - 1)
ReDim replaces the current allocation, so existing values are lost unless you include Preserve. To enlarge an existing dynamic array while keeping its contents, use:
ReDim Preserve varArray(UBound(varArray) + 10)
With Preserve, VBA can change only the upper bound of the final dimension. It cannot change the number of dimensions or resize an earlier dimension while retaining existing values.
Choose a Specific Element Type When You Can
A Variant array is flexible, but it uses more memory than a typed array. Each numeric Variant element uses 16 bytes, and each string Variant element uses 22 bytes.
Use Variant when the values genuinely have different types or when receiving the result of Array(). Use a specific type when every element has the same purpose and data type.
Enter Excel Array Constants in Worksheet Formulas
Excel array constants are values enclosed in braces inside a formula. They are entered in worksheet cells, not directly as VBA expressions. Microsoft’s Excel array constant documentation covers the worksheet syntax and entry behavior.
Enter Values Across One Row
To enter five values horizontally, select a starting worksheet cell and type:
={1,2,3,4,5}
In Excel versions that support dynamic arrays, press Enter after entering the formula in one cell. Excel spills the results into adjacent cells.
In an older Excel version without dynamic arrays, first select an output range with the same number of rows and columns as the array constant, enter the formula, and press Ctrl+Shift+Enter. Selecting a range that is too small omits values; selecting one that is too large produces #N/A in extra cells.
Enter Values in Rows and Columns
Commas separate columns, while semicolons start a new row. This Excel array constant creates a rectangular result:
={1,2,3,4;5,6,7,8;9,10,11,12}
Excel array constants can be one-dimensional or two-dimensional. You cannot create a three-dimensional array constant or nest one array constant inside another.
Text values need double quotation marks:
={"Quarter 1";"Quarter 2";"Quarter 3"}
Put an Excel Array Formula Into a Cell From VBA
When VBA writes an Excel formula, the braces belong inside the formula string. They remain worksheet formula syntax, even though VBA is assigning the formula.
This macro writes a formula that multiplies values in A1:E1 by an Excel array constant and returns the sum in F1:
Worksheets("Sheet1").Range("F1").FormulaArray = "=SUM(A1:E1*{1,2,3,4,5})"
Replace "Sheet1" with the worksheet name in your workbook. The formula returns one value, so assigning it to a single cell is appropriate.
Range.FormulaArray has a 255-character limit. If an array formula exceeds 255 characters, simplify it with helper cells, named formulas, or separate calculation steps rather than trying to build one very long FormulaArray string.
Check Common VBA Array Errors
Most array problems come from mixing up VBA syntax, worksheet syntax, and index bounds.
Compile Errors From Incorrect Constant Syntax
The following Const declaration is not valid because VBA requires a scalar compile-time constant:
Const Statuses = Array("Queued", "Running")
Use a normal variable instead:
Dim statuses As Variant
statuses = Array("Queued", "Running")
If multiple procedures need the values, use a module-level Private variable and initialize it in a setup procedure, or return the values from a function.
Subscript Out of Range Errors
A “Subscript out of range” error often means code is reading an index that does not exist. Avoid hard-coding an assumed first or last index.
For i = LBound(statuses) To UBound(statuses)
Debug.Print statuses(i)
Next i
Formula Braces in the Wrong Place
Use braces directly in an Excel worksheet formula:
={1,2,3}
Use Array() for a VBA list:
values = Array(1, 2, 3)
Use braces inside a quoted formula string when assigning a worksheet array formula through FormulaArray:
Range("A1").FormulaArray = "=SUM({1,2,3})"
Before saving the workbook, compile the VBA project through Debug > Compile VBAProject, run the procedure, and verify both the Immediate window output and the target worksheet cells. Save the workbook in a macro-enabled format if the VBA code must remain available.
Frequently Asked Questions
What Is an Array in Excel?
An array in Excel is a collection of values that a formula can process or return together. An Excel array constant uses braces, such as ={1,2,3,4,5}, while a range reference such as A1:A5 can also supply an array of values to a formula.
Is VBA Still Relevant in 2026?
Yes, VBA remains useful for maintaining and automating existing desktop Excel, Word, Access, and Outlook workflows. It is especially practical when a workbook already contains macros or when users need automation that runs inside the Office desktop apps. For browser-based collaboration and cloud-first workflows, other automation tools may be a better fit.
What Is the Purpose of Using Arrays?
Arrays keep related values under one variable name and let code process them with indexes and loops. They are useful for lists of labels, imported worksheet values, lookup data, and calculated results. A dynamic array is useful when the final number of values is not known until the macro runs.
Can I Use the Same Array Syntax in Excel and VBA?
No. In VBA, use Array(1, 2, 3) or declare an array with Dim. In an Excel worksheet formula, use ={1,2,3}; for a vertical Excel array constant, use semicolons such as ={1;2;3}.
