Ad Clicks :Ad Views : Ad Clicks :Ad Views : Ad Clicks :Ad Views : Ad Clicks :Ad Views :
    Excel formulas and tutorials

    Excel formulas and useful tools

    Home / VBA / Excel VBA Macro

    Excel VBA Macro

    /
    /
    /
    1248 Views

    This is a tutorial for anyone wanting to learn how to write their first excel vba macro. These macros are very useful when we need to do a lot of manual work on large data tables and these manual actions can be automated by using a macro to execute every operation that we usually did with the mouse and keyboard and took us a few hours to complete.

    Open an Excel file, right click the current Sheet name and select View Code.

    excel-vba-macro-tutorial

    Microsoft Visual Basic for Applications (VBA) opens and you are ready for your first macro.

    microsoft excel vba macro tutorial

    Let’s say that we have the following range of numbers and we need a macro to verify each number if it’s greater that 50, then write in the next right cell a message (“Good number”) and also change the background of the cell into some color (Red).

    vba-macro-exercise

    The code is in the picture, but I will let you download the excel file at the end of this article.

    first-macro-excel

    Make sure that you save the excel file as .xlsm or in the old excel format .xls, as the .xlsx extension doesn’t save the macro code behind the excel workbook.

    Run the excel vba macro in the worksheet by selecting Macros from Developer tab and click on Run. If you don’t have Developer tab, you must go to Excel Options, select Customize Ribbon and check the box beside Developer in the table to the right.

    running-excel-macro-vba

    The result should look like this:

    result-of-excel-vba-macro

    You can also insert a button to run the vba macro with one click. The button you need is in the upper left of the list bellow. A dialog box with all the available macros will open and you can select your macro from that list to be attached to the new button.

    insert-button-for-macro

    my-fisrt-macro-button

    I hope that this tutorial was helpful and you are on the right path to becoming a great VBA programmer. Please leave a comment bellow for me to evaluate the quality of this article.

    You can find here a great resource for your VBA study.

    Enjoy!

    [paypal_donation_button]

     
    • Facebook
    • Twitter
    • Google+
    • Linkedin
    • Pinterest

    Leave 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.

    This div height required for enabling the sticky sidebar