Excel VBA. Microsoft Excel is an extremely powerful tool that you can use to manipulate, analyze, and present data.

Similar documents
This chapter is intended to take you through the basic steps of using the Visual Basic

BASIC MACROS IN EXCEL Presented by IGNACIO DURAN

Civil Engineering Computation

EXCEL BASICS: MICROSOFT OFFICE 2010

EXCEL BASICS: MICROSOFT OFFICE 2007

Microsoft How to Series

VBA Excel 2013/2016. VBA Visual Basic for Applications. Learner Guide

You can record macros to automate tedious

Module 1 - EHA Shortcut Add-in - 1

EHA Add-Ins and Keyboard Shortcuts

The clean-up functionality takes care of the following problems that have been happening:

Explore commands on the ribbon Each ribbon tab has groups, and each group has a set of related commands.

ACCT 133 Excel Schmidt Excel 2007 to 2010 Conversion

VBA Collections A Group of Similar Objects that Share Common Properties, Methods and

Excel 2013 for Beginners

BASIC EXCEL SYLLABUS Section 1: Getting Started Section 2: Working with Worksheet Section 3: Administration Section 4: Data Handling & Manipulation

Interim Standards New Directions Workbook One EASI Tool Excel Support Document Contents:

COPYRIGHTED MATERIAL. Making Excel More Efficient

Microsoft Excel 2013 Unit 1: Spreadsheet Basics & Navigation Student Packet

Macros enable you to automate almost any task that you can undertake

Microsoft Excel 2010 Training. Excel 2010 Basics

Introduction to Microsoft Office 2007

Customizing the Excel 2013 program window. Getting started with Excel 2013

2. create the workbook file

Getting started 7. Writing macros 23

Macros enable you to automate almost any task that you can undertake

Microsoft Excel - Macros Explained

Excel Tables and Pivot Tables

Mastering the Actuarial Tool Kit

DOWNLOAD PDF EXCEL MACRO TO PRINT WORKSHEET TO

Introduction... 1 Part I: Getting Started with Excel VBA Programming Part II: How VBA Works with Excel... 31

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Maximizing the Power of Excel With Macros and Modules

Excel Select a template category in the Office.com Templates section. 5. Click the Download button.

If An Excel Worksheet Is In Manual Calculation Mode Press F9 To Recalculate

Writing Excel Macros: Automating Excel To Work For You By PhD Steven Roman

Basic tasks in Excel 2013

Using Microsoft Excel

Introduction to macros

EXCEL BASICS: PROJECTS

The Excel Project: Excel for Accountants, Business People... from the Beginning Duncan Williamson

Microsoft Excel 2007

Introduction. Understanding charts. Excel 2016

Using Microsoft Excel

I OFFICE TAB... 1 RIBBONS & GROUPS... 2 OTHER SCREEN PARTS... 4 APPLICATION SPECIFICATIONS... 5 THE BASICS...

VISUAL BASIC 2 EDITOR

Beginning Excel. Revised 4/19/16

Macros in Excel: Recording, Running, and Editing

As you probably know, Microsoft Excel is an

download instant at

MICROSOFT OFFICE. Courseware: Exam: Sample Only EXCEL 2016 CORE. Certification Guide

Advanced Excel Macros : Data Validation/Analysis : OneDrive

PART 7. Getting Started with Excel

Inserting or deleting a worksheet

Advanced Financial Modeling Macros. EduPristine

Microsoft Power Tools for Data Analysis #04: Power Query: Import Multiple Excel Files & Combine (Append) into Proper Data Set.

Create your first workbook

Using Microsoft Excel

Introducing Microsoft Office Specialist Excel Module 1. Adobe Captivate Wednesday, May 11, 2016

Creating an expenses record spreadsheet in Excel


Excel Advanced

3/31/2016. Spreadsheets. Spreadsheets. Spreadsheets and Data Management. Unit 3. Can be used to automatically

EVALUATION COPY. Unauthorized Reproduction or Distribution Prohibited

Excel Vba Manually Update Links Automatically On Open File Ignore

Lesson 2. Using the Macro Recorder

Excel 2007 Fundamentals

This book is about using Microsoft Excel to

My Top 5 Formulas OutofhoursAdmin

Excel 2013 Beyond TheBasics

Using macros enables you to repeat tasks much

Civil Engineering Computation

Formulas, LookUp Tables and PivotTables Prepared for Aero Controlex

Office 2010: Transition from Office Contents. Moving to Microsoft Office Microsoft Office 2010 Project Transition from Office 2003

Integrating Microsoft Office Learn about object linking and embedding (OLE) Tutorial 1 Integrating Word and Excel

Microsoft Excel 2010 Level 1

1: Getting Started with Microsoft Excel

Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet

Office 2007 Overview

COMPUTER SHORTCUTS Universal Help in almost every Windows program. Highlights from current position to end of line.

Switches between worksheet and menu / Ribbon. Calculates all worksheets in all open workbooks. Highlights shortcut keys of Menu and Ribbon items.

Intermediate Excel 2003

Excel 2016 for Mac Financial Analysis with Microsoft Excel, 8 th Edition Mac User Guide

Table of Contents. 1. Creating a Microsoft Excel Workbook...1 EVALUATION COPY

MICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTRODUCTION

Skills Exam Objective Objective Number

Rev. C 11/09/2010 Downers Grove Public Library Page 1 of 41

How to use the adjustment row height of the Excel add-in "AutoFitRowEx"

3. (1.0 point) To quickly switch to the Visual Basic Editor, press on your keyboard. a. Esc + F1 b. Ctrl + F7 c. Alt + F11 d.

Microsoft Excel 2007 Macros and VBA

Getting Acquainted with Office 2007 Table of Contents

Microsoft Excel 2007 Lesson 7: Charts and Comments

Excel VBA: For Non-Programmers (Programming In Everyday Language) (Volume 1) PDF

CS 200. Lecture 07. Excel Scripting. Miscellaneous Notes

Contents. Group 3 Excel Handouts 2010

Excel 2007 New Features Table of Contents

Excel Macros, Links and Other Good Stuff

Using Excel 2011 at Kennesaw State University

Introduction to Microsoft Excel 2010

Chapter-2 Digital Data Analysis

Transcription:

Excel VBA WHAT IS VBA AND WHY WE USE IT Microsoft Excel is an extremely powerful tool that you can use to manipulate, analyze, and present data. Sometimes though, despite the rich set of features in the standard Excel user interface (UI), you might want to find an easier way to perform a mundane, repetitive task, or to perform some task that the UI does not seem to address. VBA is the acronym for Visual Basic for Applications. It is an integration of the Microsoft's event-driven programming language Visual Basic with Microsoft Office applications such as Microsoft Excel, Microsoft Word, Microsoft PowerPoint and many more. By running Visual Basic IDE (Integrated Development Environment) within the Microsoft Office applications, we can build customized solutions and programs to enhance the capabilities of Microsoft Office Applications. Office applications like Excel have Visual Basic for applications (VBA), a programming language that gives you the ability to extend those applications. VBA works by running macros, step-by-step procedures written in Visual Basic. Learning to program might seem intimidating, but with some patience and some examples such as the ones in this course, many students find that learning even a small amount of VBA code makes their work easier and gives them the ability to do things in Office that they did not think were possible. Once you have learned some VBA, it becomes much easier to learn a whole lot more so the possibilities here are limitless. By far the most common reason to use VBA in Excel is to automate repetitive tasks. For example, suppose that you have a few dozen workbooks, each of which has a few dozen worksheets, and each of those needs to have some changes made to it. The changes could be as simple as applying new formatting to some fixed range of cells or as complex as looking at some statistical characteristics of the data on each sheet, choosing the best type of chart to display data with those characteristics, and then creating and formatting the chart accordingly. Either way, you would probably rather not have to

perform those tasks manually, at least not more than a few times. Instead, you could automate the tasks by using VBA to write explicit instructions for Excel to follow. VBA is not just for repetitive tasks though. You can also use VBA to build new capabilities into Excel (for example, you could develop new algorithms to analyze your data, then use the charting capabilities in Excel to display the results), and to perform tasks that integrate Excel with other Office applications such as Microsoft Access 2010. In fact, of all the Office applications, Excel is the one most used as something that resembles a general development platform. In addition to all the obvious tasks that involve lists and accounting, developers use Excel in a range of tasks from data visualization to software prototyping. HOW TO USE VBA But before we get started, let's begin by making sure that the tools we need are visible. If you can see the Developer menu in excel then you can skip the following, otherwise, please read the following. Click on File > Options > Customize the Ribbon and then check "Developer". A new tab (Developer) will be added:

HOW TO RUN VBA EDITOR? To work with VBA code, we'll need an editor, which is installed by default. You can open it by pressing the shortcut key combination "Alt F11" or choose a sheet and right click on its name and choose view code or you can go the developer menu and choose visual basic icon (the icon to the left) How to display and hide main windows: Click on the menu view, then click on the window name to show it. To close the window, simply click on the x button on the top right corner of it.

Project Window This window will show you all the files that you have opened. The Project Window uses a tree view where you can drill down into each file that you have open and see the areas in which you can insert VBA code. Notice that in my screenshot above that there are two files that are open in my Excel application: Book1 (a workbook) and VBHTMLMaker (an add-in). In Book1 you can see 3 subfolders: Microsoft Objects -This folder houses a code area for your workbook (ThisWorkbook), and your workbooks spreasheets (Sheet1) Forms - This folder stores any userforms that you create. I touched a little bit on this in Lesson One so I won't repeat myself here. If you do not see this folder you can add it by right clicking anywhere within the projects folder tree and going to Insert -> Form. Modules - A Module folder stores you macro and function code. If you do not see this folder then that means that the project most likely does not have any macro code in it (note: there can still be code stored in the forms folder or in the Objects folder). You can add this folder by right clicking anywhere within the projects folder tree and going to Insert -> Module. Properties Window The Properties Window will allow you to modify certain aspects of whatever object, form, or module you have highlighted. Typically, the only thing I change using this window is the Name field. This is a good idea because you can give your modules or forms a more meaningful name than the default names that the Visual Basic Editor provides. Custom names in the Name field can only be one word in length. Code Writing Area This is where the magic happens! In this area you can actually write and edit your VBA code. Each macro must begin with a Sub statement (which is opened with Sub [insert your macro name] ( ) and closed with End Sub). Notice also that the VBA Editor color-codes some key words in a few different colors. This helps make your code more organized. I have two major tips that I like to share with people when they are first learning to write VBA code:

Use Indentations - Always try to use indentations (via the Tab key) within your code. There are various methodologies to tabulating code but as long as you are consistent and it makes sense it will help you enormously when you are trying to add to or debug your code. It also helps when someone else is trying to help you with your code. Write in Lowercase - If you haven't noticed already, every word in the VBA language has at least one capitalize letter. How is this an advantage? Well, the Visual Basic Editor is not case sensitive and it likes to correct you when it can. This means that is you type in "workbook", the editor will automatically change it to "Workbook". My rule of thumb is to type everything in lowercase and if the VB editor doesn't capitalize at least one letter, I know that I either misspelled that word or that word is not defined. Having the Visual Basic Editor correct every word I type has really made my code less buggy and prevent a lot of frustration over the years. Immediate Window I like to refer to this area as my piece of scratch paper. The Immediate window lets you do all sorts of tests while writing and running your code. You can use the code Debug.Print to tell VBA to send the information that follows to the Immediate window. This could be the output value of a function, the value of a cell, or what a current application property is set to. When I first began writing VBA code I had no idea the Immediate window ever existed (it's usually hidden by default but you can use the shortcut Ctrl + g to view it), but once learned everything it could do I never stopped incorporating its functionality into my code writing and testing processes. Watch Window The Watch Window is kind of like an X-ray machine. It will show you all the data that is stored inside a variable! Some variables (like the ones you create in your code) will not have very much data stored in them. However, if you were to "watch" a variable that was assigned to a cell, you would see a whole bunch of data (font color, value, height, fill color, etc...). This is mostly usefully when you are trying to debug your code and want to understand what value your variable has at any given point in your code.

In order to watch a variable, you need to highlight your variables text and click the Add Watch button (this is the eyeglasses icon located on the debugging toolbar). You should then see your variable appear in the Watch Window. Once you start running through your code and load a value to your variable, you should see an option (plus sign) to drill down or expand out the contents that is now stored in the variable. SOURCES: http://vbatricksntips.blogspot.in/p/blog-page.html https://www.thespreadsheetguru.com/vba-intro/the-visual-basic-editor