

- #Microsoft visual basic for excel 2010 replace how to#
- #Microsoft visual basic for excel 2010 replace code#
Step 2) Select the Excel sheet & Double click on the worksheet Under Developer tab from the main menu, click on “Visual Basic” icon it will open your VBA editor.
#Microsoft visual basic for excel 2010 replace how to#
Test your program as shown in the animated image belowįollowing steps will explain how to use VBA in Excel.
#Microsoft visual basic for excel 2010 replace code#
Click on save and close the code window.The following image shows the complete source code “WorksheetFunction.Pmt(…)” WorksheetFunction is the function used to access all the functions in excel.“monthly_rate = Range(“B6”).Value / Range(“B5″).Value” Range is the function used to access excel cells from VBA, Range(“B6”).Value makes reference to the value in B6.“Dim monthly_rate As Single,…” Dim is the keyword that is used to define variables in VBA, monthly_rate is the variable name, Single is the data type that means the variable will accept number.Number_of_periods = Range("B4").Value * Range("B5").ValueĮmi = WorksheetFunction.Pmt(monthly_rate, number_of_periods, -loan_amount) Monthly_rate = Range("B6").Value / Range("B5").Value Give the button macro name btnCalculateEMI_ClickĮnter the following code Dim monthly_rate As Single, loan_amount As Double, number_of_periods As Single, emi As Double It’s the actual loan amountĬreate the GUI using excel cells as shown belowĪdd a command button between rows 7 and 8 It’s the loan term multiplied by number of payments per year “nper” it is the total number of payments.It’s the interest rate divided by the number of payments per year The PMT function works as follows =PMT(rate,nper,pv) You can use the PMT function to compute the above. The good news is excel already took care of the above problem. The above formula is complex and can be written in excel. The following image shows the formula for calculating EMI. It’s the monthly amount that you repay when you get a loan. EMI is the acronym for Equated Monthly Instalment. In this tutorial exercise, we are going to create a simple program that calculates the EMI. Right click on button 1 and select edit textĬongratulations, you just created your first VBA program in excel Step by step example of creating a simple EMI calculator in Excel.Your complete code window should now look as follows “ MsgBox “Hello ” + name” calls the built in function MsgBox that display Hello and the entered name.The entered name is then stored in the name variable. “name = InputBox(“Enter your name”)” calls the built in function InputBox that displays a window with the caption Enter your name.The variable will accept text, numeric and other characters because we defined it as a string “Dim name as String” creates a variable called name.You will get the following VBA code windowĮnter the following instruction codes Dim name As String.Rename the macro name to btnHelloWorld_Click.You will get the following dialogue window Select a command button as shown in the image belowĭraw the command button anywhere on the worksheet.Click on INSERT drop down box under controls ribbon bar.Save it in an excel macro enabled worksheet format *.xlsm.This tutorial assumes you have completed the tutorial on Macros in excel and have enabled the DEVELOPER tab in excel.

We will create a basic VBA program that displays an input box to ask for the user’s name then display a greeting message While sub stands for a subroutine which we will learn in the later part of the tutorial. Here the name is the name you want to assign to your program. All program in VBA has to start with “Sub” and end with “End sub”. Now we will demonstrate how to program in VBA programming language. You will now be able to see the DEVELOPER tab in the ribbon VBA Hello World! As you work with VBA Excel, you will be required to declare variables too just like in algebra classes They can also be changed to say 4 and 2 respectively. In this expression, x and y are variables.

VBA is easy to learn, and it has easy to use User Interface in which you just have to drag and drop the interface controls. VBA enables you to use English like statements to write instructions for creating various applications.
