VBA Constant Expression Required

Associated Files Download Links

We covered arrays, static arrays and dynamic arrays in a previous tutorial.  We are going to look at a common error associated with static arrays called Constant Expression Required. This error is generated when you try to use a static array instead of a dynamic array as shown in the code below:

Static array instead of dynamic array

The static array needs to have constants used to set it since it is fixed.
The way to resolve this error is to use a Dynamic array variable instead. You would use the ReDim keyword every time you want to resize the array. This is shown in the code below:


Read more about Dynamic array variables in our Array variable tutorial.

You may also like some of this related content...

A VBA Static variable retains its value even when the procedure ends. Declaring a Static
We covered an introduction to variables and constants in our VBA Data Types – Variables and
We have already covered an introduction to variables, constants and VBA data types in an
We are going to cover Global Variables, in this tutorial. A variable in VBA can
We have already gone over what variables and constants are, in our VBA Data Types