Book Image

Data Analysis and Business Modeling with Excel 2013

Book Image

Data Analysis and Business Modeling with Excel 2013

Overview of this book

Table of Contents (18 chapters)
Data Analysis and Business Modeling with Excel 2013
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
10
Creating Interactive Spreadsheets Using Tables and Slicers
Index

Your very first "Hello World" VBA script


We are going to start with a very simple script and then get into coding some useful VBA code. To start with, we are simply going to create a macro that displays a message box when it runs. These sections will help you visualize the steps needed to code, create, and deploy your macros.

  1. Press the ALT + F11 keys to open the VBA editor in case you closed this window after our last section.

  2. Click on the Insert menu and select the Module option, as shown in the following screenshot. You need to create a module before you can begin writing any code. In other words, modules hold the VBA code.

    You will get a new window and have an object explorer that looks similar to the following screenshot. You can change the name of Module1, but for this section, we are going to keep the default name.

  3. Type the following code into the module:

    Sub Hello_World()
    
        ' My first VBA sub procedure
        MsgBox ("Hello World")
    
    End Sub

    Can you explain this code to me?

    On line one, we...