Excel Macro Tutorial : How to write Excel Macro – Your First Excel Macro

.

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

My First Simple Macro

My First Simple Macro



Step 4. In the A1, A2 and A3, you have entered 25, 30 and 4 respectively.

My First Simple Macro

My First Simple Macro



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.

My First Simple Macro

My First Simple Macro



Step 7.Click on Run

My First Simple Macro

My First Simple Macro



Step 7.After running the Macro, See the Result.

My First Simple Macro

My First Simple Macro



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

My First Simple Macro

My First Simple Macro



Step 8.Now Result is changed after running the Macro.

My First Simple Macro

My First Simple Macro



Happy Macro Writing…. 🙂 🙂

 
To Check out more Excel Macro Tutorials, visit Excel Macro Tutorial

Buy a coffee for the author

Adsense

Download FREE Tools and Templates

There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.

Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide

In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...

How to Declare a Public Variable in VBA
How to Declare a Public Variable in VBA

While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...

How to Copy content from Word using VBA

As many of us want to deal with Microsoft Word Document from Excel Macro/VBA. I am going to write few articles about Word from Excel Macro. This is the first article which opens a Word Document and read the whole content of that Word Document and put it in the Active...

What is Excel Formula?

Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).

You May Also Like…

11 Comments

  1. Shagun

    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?

    Reply
    • Vishwamitra Mishra

      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?

      Reply
    • Deepak

      you have to go on individual sheet and then you have to run macro.

      Reply
  2. nishant

    Very nice walkthrough. Thanks a ton

    Reply
  3. sohan

    please suggest any easy helping book and link for macros and vba

    Reply
  4. Ashish

    Thanks ……… do you have any practice for beginers

    Reply
  5. Hemanth

    Awesome Exercise and material. Thanks a lot

    Reply
  6. LakshmiNarayana

    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

    Reply
  7. Shanoji

    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.

    Reply
  8. thinhvd

    Shortcut Alt+F11 to chang view VBA window and Excel window

    Reply

Trackbacks/Pingbacks

  1. Welcome to LearnExcelMacro.com Excel VBA Basics : All about Debugging Excel VBA code - […] root cause of the problem. This article should have been written for you long back.. right after your first…
  2. Top 10 Useful Excel Macro [VBA] Codes Examples - [For Beginners] - Let's excel in Excel - […] If you do not know – how to use these snippets in your excel sheet, refer to my beginner’s…

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join and get a FREE! e-Book

Don't miss any articles, tools, tips and tricks, I publish here

You have Successfully Subscribed!

Pin It on Pinterest