Excel Functions Tutorials
- Excel Tips
- Excel vs Access
- Excel Rows vs Columns
- Apple Numbers vs Excel
- 3D Reference in Excel
- Absolute Reference in Excel
- Mixed References in Excel
- Excel Reference to Another Sheet
- Array Formulas in Excel
- Arrays in Excel VBA
- Auto Numbering in Excel
- AutoFit in Excel
- AutoCorrect in Excel
- AutoSave in Excel
- AutoRecover in Excel
- Bullet Points in Excel
- Break Links in Excel
- Barcode in Excel
- Change Case in Excel
- CAGR Formula in Excel
- Calculate Age in Excel
- Calculate Percentage in Excel Formula
- Cell Reference in Excel
- Checklist in Excel
- Circular Reference in Excel
- Column Sort in Excel
- Column Lock in Excel
- Move Columns in Excel
- Custom List in Excel
- Consolidate in Excel
- Combine Cells in Excel
- Compare Two Columns in Excel
- Compare and Match Columns in Excel
- Compound Interest Formula in Excel
- Convert Columns to Rows in Excel
- Convert Date to Text in Excel
- Convert Numbers to Text in Excel
- Convert Text to Numbers in Excel
- Convert Excel to CSV
- Count Characters in Excel
- Count Rows in Excel
- Count Unique Values in Excel
- Countif not Blank in Excel
- Create Templates in Excel
- Family Tree in Excel Template
- Custom Number Format in Excel
- Delete Row Shortcut in Excel
- Divide in Excel Formula
- Drop Down List in Excel
- Dynamic Tables in Excel
- Dashboard in Excel
- KPI Dashboard in Excel
- Date to Text in Excel
- Date Format in Excel
- Database in Excel
- Delta Symbol in Excel
- $ Symbol in Excel
- Excel Column to Number
- Edit Drop-Down List in Excel
- Equations in Excel
- Exponents in Excel
- Excel Extensions
- Excel Translate
- Excel Not Responding
- Excel Find and Replace
- Find and Select in Excel
- Excel Subtraction Formula
- Excel Formula for Grade
- Excel as Calculator
- Excel Formula Not Working (Updating)
- Excel Table Styles & Formats
- Excel vs Google Sheets
- External Links in Excel
- Excel Alternate Row Color
- Excel Worksheet Tab
- Extract Number from String Excel
- Evaluate Formula in Excel
- Find Duplicates in Excel
- Finding Links in Excel
- Filter Shortcut in Excel
- Formatting in Excel
- Format Numbers to Millions & Thousands in Excel
- Format Phone Numbers in Excel
- Formula Errors in Excel
- Fractions in Excel
- Frequency Distribution in Excel
- Group in Excel
- Group Worksheets in Excel
- Group Columns in Excel
- Hide Formula in Excel
- Hiding a Column in Excel
- Highlight Every Other Row in Excel
- Highlight Duplicates in Excel
- How to Create a Formula in Excel?
- How to Create an Excel Spreadsheet?
- How to Add Text in Excel Formula?
- How to Create Dashboard in Excel?
- How to Copy Sheet in Excel?
- How to Delete Pivot Table?
- How to Calculate Percentage Increase in Excel?
- How to Multiply in Excel Formula?
- How to Unhide Columns in Excel?
- Insert Date in Excel
- Insert Calendar in Excel
- Import Data into Excel
- Insert Comment in Excel
- Insert Hyperlinks in Excel
- Insert Multiple Rows in Excel
- Insert Row Shortcut in Excel
- Insert New Worksheet in Excel
- Insert (Embed) an Object in Excel
- Insert Image in Excel Cell
- Insert Page Break in Excel
- Line Breaks in Excel
- Linear Interpolation in Excel
- Leading Zeros in Excel
- Last Day of the Month in Excel
- Logical Operators in Excel
- Lookup Table in Excel
- Mortgage Calculator in Excel
- Moving Average in Excel
- Not Equal to in Excel
- Numbering in Excel
- Name Manager in Excel
- Page Numbers in Excel
- Page Break in Excel
- Personal Budget Template in Excel
- Project Management Template in Excel
- Percentage Difference in Excel (Increase / Decrease)
- Pivot Table Calculated Field & Formula
- Pivot Table Sort
- Pivot Table From Multiple Sheets
- Print Comments in Excel
- Print Excel Gridlines
- Print in Excel
- Print Preview in Excel
- Print Area in Excel
- Print Titles in Excel
- Print Labels From Excel
- Project Timeline in Excel
- Protect Sheet in Excel
- Ratio in Excel Formula
- Random Numbers in Excel
- Randomize List in Excel
- Refresh Pivot Table in Excel
- Relative References in Excel
- Remove Blank Rows in Excel
- Remove Duplicates in Excel
- Remove Duplicates from Excel Column
- Remove Hyperlinks in Excel
- Remove Space in Excel
- Remove Leading Spaces in Excel
- Remove Watermark in Excel
- Row Limit in Excel
- Rows and Columns in Excel
- Rows to Columns in Excel
- Row Header in Excel
- Search in Excel
- Search For Text in Excel
- Share an Excel Workbook
- Shortcut to Merge Cells in Excel
- Show Formula in Excel
- Split Cells in Excel
- Separate Text in Excel
- Strikethrough in Excel
- Strikethrough Text in Excel
- Sum by Color in Excel
- Subscript in Excel
- Superscript in Excel
- Themes in Excel
- Timesheet Calculator in Excel
- Top 20 Keyboard Shortcuts in Excel
- Unmerge Cells in Excel
- Uppercase in Excel
- Word Count in Excel
- Word Cloud in Excel
- Watermark in Excel
- Weighted Average in Excel
- Wildcard in Excel
- Financial Functions in Excel (17+)
- Logical Functions in Excel (15+)
- TEXT Functions in Excel (29+)
- Lookup Reference in Excel (44+)
- Maths Functions in Excel (52+)
- Date and Time Function in Excel (22+)
- Statistical Function in Excel (50+)
- Information Functions in Excel (5+)
- Excel Charts (48+)
- Excel Tools (98+)
- VBA (162+)
In general one variable is supposed to hold a single value at a time, but when we want to store multiple values in a single variable then such type of variable is known as array variable, to use an array variable in VBA we need to declare or define it first, we can define the array variable with its length or without its length.
VBA Arrays (Table of Contents)
- Arrays in VBA for Excel
- 5 Different Types of Arrays in VBA Excel
- How to Use Arrays in VBA Excel (with examples)
Arrays in VBA Excel
Suppose if we have data that contains hundreds of rows and multiple columns and we need to create a code that will use the data. Now, in this case, we have to create multiples of the variable that will fetch the value from the cells and give to the program. This will be very tiring to create this much of variable and hence in such cases, we use Arrays in excel.
Excel VBA Arrays hold the data set in their memory and do not need us to declare the variable for each of the value that needs to be fetched from the data. The need of using Arrays in VBA Excel is because of the fact that in excel variable are designed to hold one value at a time, however, when multiple values are stored by a variable it becomes an array.
- Creating an Array is like creating a separate memory unit in excel that can hold the data in it. For creating an Array the data must be of the same type.
- The Excel VBA Arrays that we give to excel must correspond to the type of data that we have. Suppose if we have data that has only rows so in this case, we will use the “One-dimensional array” and if data contains columns also then we have to use “Two-dimensional arrays” as they are only capable of holding the values from the rows and columns.
- Arrays also have to function to work as dynamic arrays or static arrays. As we give dynamic range to the formula we can also make the Arrays variable. Dynamic arrays will have the functionality to include infinity number of rows and columns. In case if the arrays that we have defined are of a static type then they can only hold limited numbers of rows and columns as defined at the time of creating the array.
Top 5 Different Types of Arrays in VBA Excel
Below are the types of arrays in VBA Excel.
#1 – Static Arrays
An array that has Predefined count of value that can be stored in it.
#2 – Dynamic array
Array with a not predefined count of value that it can handle.
#3 – One-dimensional Array
An array that can hold only data either from rows or columns.
#4 – Two-dimensional Array
An array that can store a value from the rows and columns.
#5 – Multidimensional Array
Excel array work on the “Mathematical rule of matrix” that is they identify the data by its location only. Suppose if we have to make VBA understand that we need “20” in cell “B3” then we have to write the code of the location as (3, 2) where the first value stands for the location of row and second value stands for the column number. In excel world these code of locations is called “Upper bound” and “lower bound”. By default the location in excel starts from one and not from zero, so excel sees “A1” as row number 0 and not row number 1.
Similarly, the columns start from zero from one and not from one.
These arrays can be defined as a static array or dynamic array. If we define them as static array this means that they cannot hold more then the variables as defined while coding them. If we are not sure about the value that is required to be memorized by the arrays we create dynamic arrays and in such cases, they can hold infinity numbers of values.
Now after we have selected the type of array that is required we will now have to enter the data in these arrays.
This data has to be given one by one to excel in below ways.
After the data is stored in these Excel VBA arrays they are ready to use as a variable in the VBA coding.
How to Use Arrays in Excel VBA (with examples)?
You can consider the following example for better understanding of Arrays in VBA:
Excel VBA Arrays can be used in many situations but they must be used when the number of variables that are to be declared is large in number and it is not feasible to declare them.
Below are some of the arrays in VBA Examples but before going to the examples we will learn to open the VBA editor by shortcut key
This will open the VBA editor, from there we have to enter the code in “This worksheet”.
Array in VBA Example #1
Choose the type of array that you want, should it be a dynamic or static array?
If we need a dynamic array then we will define the dimension as “variant”.
If we need a static array then we will define a dimension as “Static”.
Array in VBA Example #2
Define the columns and rows that you want the array to store.
If we have entered “1” in the bracket this means that array can hold 2 rows value as excel counting starts from zero.
If we need columns and rows also then we need to define both of them.
Here “1 to 2” means that two rows and “1 to 3” means that three columns.
Here we have changed the rule of how excel counts rows and asked it to count from “1” and not from zero.
Array in VBA Example #3
The input of data in the array.
The data has to entered cells wise. Here the data is to be entered in form of (I,j) where “I” means the row and “J” means the column.
So “a (1,1”) means that cell ”A1”
Array in VBA Example #4
Closing the code.
After the data has been entered for the array, the last step will be to close the code.
Things to Remember About Arrays in VBA Excel
- By default, Excel will count the rows starting from zero. This means that “2” in place of “I” will means 3 rows and not 2 rows. This same applies to “J”.
- The data that has to be entered for the array must be started from (0, 0) that is from the first row and first column.
- In case if we are using the dynamic arrays then this will need the function of “REDIM” to define the number of rows and columns that are required to be memorized.
- In case of creating a two-dimensional array then we have to use “Integer” as the dimension.
- The excel file needs to be saved in the version that is “Macro compatible” else the coding that we have done in VBA will vanish and will not run the next time.
This has been a guide to Arrays in Excel VBA. Here we discuss the different types of VBA Arrays, how to use Arrays in VBA Excel along with excel example and downloadable excel templates. You may also look at these useful excel tools –