You are on page 1of 92

Getting Started with VBA

in Excel
Excel Ninjaz Secrets only at the Manila Excel Ninjaz
Meetup
Rowen Remis R. Iral
http://wenup.wordpress.com
2017 November 16
Rowen Remis Iral

Certified IT Engineer
Data Science / Analytics freelancer
Other Interests:
Marketing

Business

Economics

Genomics / Bioinformatics
Motivation
I am always doing
that which I
cannot do, in
order that I may
learn how to do
it.
-Pablo Picasso
Agenda

What is VBA
Uses of VBA
Setting up Your Excel Ninja Machine
Tour of the VBA IDE
Hello World
Excel Objects
What is VBA?
Visual Basic for Applications (VBA)

Microsofts Event Driven Programming


Language (Visual Basic) in Microsoft
Office Applications
VBA is
an Automation and
Programming Tool in
an Office Application
Uses of VBA
Keeping lists of things, such as customer
names, students grades, or holiday gift ideas

Budgeting and forecasting

Analyzing scientific data

Creating invoices and other forms

Developing charts from datatabmark


Setting up Your Excel Ninja Machine
- Enabling VBA

File, Options and select Customise


the Ribbon.

Tick the Developer box to allow


the Developer icon to appear.
Setting up Your Excel Ninja Machine

Click File menu


Setting up Your Excel Ninja Machine

Click Options
Setting up Your Excel Ninja Machine

Click
Customize Ribbon
Setting up Your Excel Ninja Machine

Main Tabs of Excel


Setting up Your Excel Ninja Machine
Under Main Tabs,
Setting up Your Excel Ninja Machine

Check Developer
Setting up Your Excel Ninja Machine
Click OK
Setting up Your Excel Ninja Machine

Now its the Developer Menu


Click Developer
Setting up Your Excel Ninja Machine

VBA was Enabled


Setting up Your Excel Ninja Machine

This is the Macros button


Setting up Your Excel Ninja Machine

Click
Visual Basic beside Macros
Alt+F11
VBA IDE
VBA IDE
VBA IDE

Menu Bar and


the Tool Bar
VBA IDE
VBA IDE

Project Explorer
VBA IDE

Object
Properties
VBA IDE

Double-Click Sheet 1
VBA IDE

This is the Code


Window
VBA IDE

Programmable Objects
VBA IDE

Current
Workbook Object
VBA IDE

Source Code Window


Hello World Sample
Hello World

Lets Code
Hello World
Select the Code
Hello World

Click the Run Button


Hello World

As Instructed
A message box
Pop-ups with
Hello world
Hello World
Click
OK to Close
Hello World Another way to Run Code

1
2
Hello World

When you
Run without Selection
Hello World

This pops up.


Hello World

Lets Rerun code


Hello World

Run
Hello World

Prompt appears
Select a Module
Hello World

Click Run
Hello World

It runs.

Click OK to close.
Hello World

Selector in
Properties Window
For Objects
Hello World

Selector for Macros


or Scope of Code
Design Mode in Main Excel
Application
Design Mode

In VBA Design Mode Button


Design Mode

Design Mode button


Design Mode

Switch to
Excel
Design Mode

Click
Design Mode
Design Mode

Click
Insert
To Insert
Controls
Design Mode

Click Button
to insert a button
Design Mode

The Draw Cursor, drag to draw a


Button control.
Design Mode

Drawing a
Button
Design Mode 2
1
Create a new
Macro code for the Button.
Design Mode

A button
was created
Design Mode

In VBA
Another way to
access Properties
Design Mode

For running
Excel files with
Macros
Design Mode

Lets get to
Design Mode
Design Mode

In VBA, a module
Was created. Module1

Module = source code


Design Mode

Code for Button1


Design Mode

Right-click the Button 1


Design Mode

Click
Assign Macro
Design Mode

Select the
Function / Macro
Design Mode

Run the Code


Design Mode

Select the
Sub Main()
Design Mode

Click Run
Design Mode

Hello World
Design Mode

Live Button with


Code or Macro
Design Mode

Click the
Button 1
Design Mode

This runs from Button 1

Click OK to close
Design Mode

Design Mode Again for


Another Button
Design Mode

Insert another
Button
Design Mode

Drag to Draw
Another Button
Design Mode
Create a
New Sub / Function Name
Design Mode

Click New button


Design Mode

Code for Button 2 / AskName


Design Mode
Run for
Testing
Design Mode

Input a Name and Click OK


Design Mode

Output
Design Mode

This part,
Well attach
Code to new
Button
Design Mode
Right-click the
New button.

Click Format Control


Design Mode

Click Alt Text, this text is a hover text.


Design Mode

Type the
Alternative
Text and Click
OK.
Design Mode

Change
Button Label

Design Mode Again for


Another Button
Design Mode
Type button label
And
click Exit Edit Text
Excel Objects
Excel Objects

Back to VBA IDE


Excel Objects

Explore VBA and


Excel Objects
Excel Objects

This is where you search and check


Excel Objects.
Thank you.

Rowen Remis R. Iral


http://wenup.wordpress.com

You might also like