

- #HOW TO WRITE A MACRO IN EXCEL THAT USES IF STATEMENTS HOW TO#
- #HOW TO WRITE A MACRO IN EXCEL THAT USES IF STATEMENTS CODE#
Go to the Green File Tab and click on Options To load the Analysis ToolPak follow these simple steps They also produce charts sometimes along with the reports. You just need to provide the data for the analysis and Analysis ToolPak uses the appropriate macro function and displays the result in the output table. You can always save your time and energy by using Analysis ToolPak. It is a data analysis tool and helps in financial, statistical and engineering data analysis.

‘special instructions to handle too many or too little purchasesĮlse statement is used when a If condition is failed. Here is an example to test the purchase condition Using If statement is really easy in VBA Macros. Few are explained below for your understanding If Then Statement There are a lot of statements to test conditions. This is used as myList(5) = 792, means it sets the value of 5th item in myList array to 792.Įverything in computer involves decision making and testing conditions. Dim myList(1 To 10) As String – This line means that you want to use a list of values which is in the form of String (Text).This is used in VBA as someNumber = 7, that means it stores 7 into the variable someNumber Dim someNumber As Integer – This tells you that you are going to use some Number variable to store Integer values only.DIM is the statement which is used to create any variable.įollowing are few examples of variables created If you want to use a variable in VBA Macros you first need to create them.
#HOW TO WRITE A MACRO IN EXCEL THAT USES IF STATEMENTS HOW TO#
Now we shall see how to use all these three in VBA Creating Variables in VBA Macros Loop – It is a set of instructions which is to be followed for particular number of times Variable – It is a small part of system’s memory which is used to store dataĬondition – It is a logical check which the computer performs to test something Understanding Variables, Conditions and Loops in VBAįirst let’s see what all the three terms mean in VBA Select the Macro Name from the list and Click on the Run buttonĮnter the necessary details to generate the report.įinally the report is generated as per your need. To run the report follow the below steps:Ĭlick on Macros Menu under the Developer tab
#HOW TO WRITE A MACRO IN EXCEL THAT USES IF STATEMENTS CODE#
Go to Developer Tab à Macros to use the Macros Menu.Įnter a Macro Name for the report and click Create Button.Įnter a code for the form between Sub and End Sub optionĪfter all these steps are done now you are all set to run the report. You can also add functions in the Code Window which is used to generate the report.Īfter the code is entered, you need to create Macros for the data. The Code is Placed between “Private Sub CommandButton1_Click()” and End Sub. In the Code Window enter the code which is used to Run the command. In this picture the Microsoft ActiveX Data Objects 2.6 Library check box is selected. To select references Tools Menu à Referencesįrom the Dialog Box select the type of Library which you want to use. To open the Code Window double click on the Command Button which is placed in the form.īefore the code is inserted you need to set a reference which will help you to access the VB database. Right click and from the properties pop up Enter the command which you want from the Captions Property.Īfter all the user interface data is entered now you need to enter the Code to generate the report. Now select the Command Button option from the Toolbox and place it in the form. Repeat the steps to add as many labels and text box you want to enter in the User Form area.

And then right click on the Text Box and in the Properties Pop Up menu enter a Name for the Text Box in the Name Property. Now select the Text box icon from the Tool Box and keep it next to the Label box.
