Dynamically Populating VBA Array Variables To Store Lists of Data
Dynamically Populating VBA Array Variables To Store Lists of Data
Method 1: Resizing
First
https://www.thespreadsheetguru.com/blog/dynamically-populating-array-vba-variables 2/10
20/4/23, 9:25 Dynamically Populating VBA Array Variables To Store Lists of Data
Sub PopulatingArrayVariable()
'PURPOSE: Dynamically Create Array
Variable based on a Given Size
End Sub
Method 2: Resizing
As You Go
This VBA method resizes the array
variable right before storing each
item. The key command here is
"Preserve". This tells the code to
https://www.thespreadsheetguru.com/blog/dynamically-populating-array-vba-variables 3/10
20/4/23, 9:25 Dynamically Populating VBA Array Variables To Store Lists of Data
Sub PopulatingArrayVariable()
'PURPOSE: Dynamically Create Array
Variable based on a Given Size
End Sub
Method 3: Creating
From A Delimited
String
Another way you can populate an
array variable is through a
delimiter. A delimiter is simply a
https://www.thespreadsheetguru.com/blog/dynamically-populating-array-vba-variables 4/10
20/4/23, 9:25 Dynamically Populating VBA Array Variables To Store Lists of Data
Sub PopulatingArrayVariable()
'PURPOSE: Dynamically Create Array
Variable based on a Given Size
End Sub
Sub PopulatingArrayVariable()
'PURPOSE: Dynamically Create Array
Variable based on a Given Size
End Sub
Method 4: Pulling
From An Excel
Table [My Favorite
Option!]
https://www.thespreadsheetguru.com/blog/dynamically-populating-array-vba-variables 6/10
20/4/23, 9:25 Dynamically Populating VBA Array Variables To Store Lists of Data
Sub PopulatingArrayVariable()
'PURPOSE: Dynamically Create Array
Variable based on a Single Columned
Table
End Sub
Any Other
Methods?
Are there any other methods you
use to populate arrays
dynamically? I would love to hear
from you in the comments section
below and maybe I can add some
other options to the ones I've
already discussed in the article.
- Chris
Founder, TheSpreadsheetGuru.com
https://www.thespreadsheetguru.com/blog/dynamically-populating-array-vba-variables 9/10
20/4/23, 9:25 Dynamically Populating VBA Array Variables To Store Lists of Data
27 Comments
1 Login
LOG IN WITH
Name
6 Share
https://www.thespreadsheetguru.com/blog/dynamically-populating-array-vba-variables 10/10