Dear Readers,
Till now we have learnt following things in Excel Macro Tutorial . In this part of Tutorial you are going to learn how to open the VBE Code Window in Visual Basic Editor of your Workbook and start writing your first macro.
1. What is Excel Macro ?
2. How to Record Macro / How to Run Macro
3. Add Developer Tab in Excel – 2007 and 2010
4. Visual Basic Editor in Excel
5. How to add different types of controls like Text Box, Radio button, button etc. in Excel
6. VBA Control Property
You have got all the basic concept about Excel Macro. So now I will show you, how you can start writing Excel Macros.
Example: You are going to write your first Excel Macro. By running that Excel Macro you will add the Value of Cell A1 and A2 and multiply that Sum with the Value of Cell A3. Store this Result in Cell A4. This is your requirement to write Macros.
Follow the below Steps, to write your first Excel Macro an Achieve the above mentioned requirement
Step 1.First go to Visual Basic Editor of your workbook (How to open Visual Basic Editor??)
Step 2.Double Click on the Sheet Name under VBA Project in right side of the Visual Basic Editor.
Step 3. Copy and Paste the below Code in the Code Window
Sub My_First_Macro()
Range("A4").Value = (Range("A1").Value + Range("A2").Value) * Range("A3").Value
End Sub
Step 4. In the A1, A2 and A3, you have entered 25, 30 and 4 respectively.
Step 5.Now after running the above macro, Sum of A1 and A2 should be multiplied with A3 and result must be stored in A4.
Step 6.Now Click on the Run Button to Run the Written Macro.
Step 7.Click on Run
Step 7.After running the Macro, See the Result.
Congratulations you have run and tested you first macro.
Step 7.Now go to your Sheet and Enter some Other Values as Input and Press Alt+F8
Step 8.Now Result is changed after running the Macro.
Happy Macro Writing…. 🙂 🙂
To Check out more Excel Macro Tutorials, visit Excel Macro Tutorial |
Hi Vishwa,
I tried this and got through 🙂 🙂
Also, when we run a macro, what do we mean by selecting the option "All open workbooks" from the dropdown.
For an instance, i have put the values for A1, A2, A3 in all the 3 sheets in the excel but it worked for only 1st sheet?
Hi Shagun,
While running a Macro, if you select the option “All open workbooks”, then it will list down all the Macros which are there in all the Workbooks. You can select any one of them and Run it.
Your second question is not clear. Can you please me explain it in detail?
you have to go on individual sheet and then you have to run macro.
Very nice walkthrough. Thanks a ton
please suggest any easy helping book and link for macros and vba
Thanks ……… do you have any practice for beginers
Awesome Exercise and material. Thanks a lot
Hi Vishwamitra,
I appreciate for Knowledge transfer.
My question is this is stick for particular cell,so if I want this for code will reflect entire cells.as well other sheets how to do.
Please respond for this question.
Regards,
Lakshmi
Hi,
I am a beginner, and if want to share excel reports to multiple email address from one dump. Can we use macro?
IF yes, please help me how to do that?
it takes a lot of manual work when I do it. If possible in macro it’ll be really helpful to reduce work time.
Shortcut Alt+F11 to chang view VBA window and Excel window
Thanks 🙂