Skip to main content

New Article

How to SUM by matching partial text in Excel

An Introduction to Array in Excel VBA

Excel VBA is a Programming language, and though it is a language, it should support Array Programming. Yes, it does. In Excel we can use Array Formula. We can also use the power of Array in Excel VBA.



What is an Array?

In a simple definition, the variable, which contains two or more values under the same variable, is called an Array. In programming language sometime you need to use lookup function in a specific list. To do this use an Array. An Array is a way to store more than one value under the same variable name. An array looks like this when it is declared:


Dim yourName(5) as Integer

In the above code, Dim is short for the word Dimension and it allows you to declare variable names and their type. Then we used a custom name yourName to store values. But how many values can store in yourName? We declared (5) that means 0 to 5 = 6 values. If we declared (1 to 5) then it will not count the 0 (zero), so that you can store 5 values under the same yourName variable. So you can also set an Array variable with 6 stored cell like below:


Dim yourName(1 to 6) as Integer




How to set values in Array?

Now to set your Array Values under the same Array Variable, follow the below code:


Dim yourName(1 to 6) as Integer

yourName(1) = 4
yourName(2) = 2
YourName(3) = 7
YourName(4) = 3
YourName(5) = 8
YourName(6) = 7

In the above code, you entered 4, 2, 7, 3, 8, 7 digits as values for each variable cell (1 to 6) under the same variable name yourName.



Run the Array values:

To test your Array values working properly or not, use the below codes in your code window:


Sub ArrTest()

Dim yourName(1 to 6) as Integer

yourName(1) = 4
yourName(2) = 2
YourName(3) = 7
YourName(4) = 3
YourName(5) = 8
YourName(6) = 7

MsgBox yourName(4)

End Sub

If you run the above program, then it will show a message box. The message box shows the value which is stored in yourName(4). That means 3:


Image 1: Result

This is the basic of Array in Excel VBA. In next I will try to explain more details with the help of real life project.


|||| Please SUBSCRIBE our YouTube Channel ||||
https://www.youtube.com/channel/UCIWaA5KCwZzBGwtmGIOFjQw

Popular posts from this blog

How to display an image in worksheet based on a List or based on IF condition?

Excel can show image on worksheet based on a specific IF condition. So, how to do it? Simple follow the below steps: Step by Step: Step 1: Insert images in your Excel Worksheet. Here I've inserted 5 different types of balls, Football, Cricket, Pool, Basketball, Tennis ball. Note that, All balls are placed into different cell. These are placed in Picture sheet. Image 1: 5 balls placed in 5 different cells and covered photo's wide and height Step 2: In the report sheet, design the report as you wish. I've designed in my way like below: Image 2: Kids asking to Donald Duck, which ball need to throw now Step 3: Make a drop down list "Games" in E6 cell in Report sheet from Data Validation. which is as below: Football Cricket Pool Basketball Tennis You can do an IF function here in E6 in Report sheet, which will meet a certain condition and returned Football, Cricket, Pool, Basketball or Tennis. Step 4: Now the tricky part is

Fiverr Microsoft Excel 2016 Skill Test and Answers 2021

This video will help you about preparing Fiverr Excel Skill Test. I've just taken this Fiverr Excel Skill Test and successfully passed with a scored 6 out of 10. I'm sharing my Fiverr Excel Skill Test and Answers 2021 video so that you can prepare yourself if you would like to give a test on Fiverr.    I have taken the Fiverr Excel Skill Test on Fiverr and obtained 6 out of 10 scores. If you take a test and pass, it will greatly help the buyer to trust you and your skills. Please note that your exam will not be exactly the same as mine because there are many more questions in the pool than 40 which appeared in my test. But I am hopeful that you will succeed in it. If you have any queries, please write them in the comment section. I will try my best to guide you.Follow this video and try to get a general idea. By following the instructions, you can successfully pass the test.    After passing the Fiverr Excel Skill Test, Fiverr shared a Excel Expert Badge on my Profile, so that

Cumulative Closing Balance like a Bank Statement in PivotTable

A Bank Employee in many case needs to calculate the Closing Balance after each transaction in PivotTable like a Bank Statement . But with the help of Calculated Field of a PivotTable , you can only calculate Field with Field . It's not possible to use a formula in Calculated Field where you can mention a single cell with Relative Reference Cell . Because a PivotTable acts like a Table format where you can work with Field or Column Name . A Helping Column (A regular column, that helps to get a partial result where formula applied) can be a good idea. But there is an option in PivotTable by which you can Calculate Cumulative . In this article I will show you, how you can do it. Calculating with Formula: Assume that, you have an Excel file with Debit and Credit transaction of an Account . Image 1: Sample Bank Statement In a Bank Statement , Month wise Cumulative Balance is important. In the Excel sheet, as above, it is very easy to use a formula and calc