Excel 2010 Bible

(National Geographic (Little) Kids) #1

887


CHAPTER


VBA Examples


IN THIS CHAPTER


Working with ranges

Working with charts

Modifying properties

VBA speed tips

M


y philosophy about learning to write Excel macros places heavy
emphasis on examples. Often, a well–thought-out example com-
municates a concept much better than a lengthy description of the
underlying theory. In this book, space limitations don’t allow describing
every nuance of VBA, so I prepared many examples. Don’t overlook the VBA
Help system for specific details. To get help while working in the VB Editor
window, press F1 or type your search terms into the Type a Question for
Help field on the menu bar.


This chapter consists of several examples that demonstrate common VBA
techniques. You may be able to use some examples directly, but in most
cases, you must adapt them to your own needs. These examples are orga-
nized into the following categories:


l (^) Working with ranges
l Working with workbooks
l (^) Working with charts
l Programming techniques to speed up your VBA code


Working with Ranges


Most of what you do in VBA probably involves worksheet ranges. When you
work with range objects, keep the following points in mind:


l (^) Your VBA code doesn’t need to select a range to do something with
the range.
l (^) If your code does select a range, its worksheet must be active.

Free download pdf