18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

VBA Examples<br />

My philosophy about learning to write Excel macros places heavy<br />

emphasis on examples. I’ve found that a well-thought-out example<br />

often communicates a concept much better than a lengthy description<br />

of the underlying theory. In this book, space limitations don’t allow describing<br />

every nuance of VBA, so I’ve prepared many examples. Don’t overlook VBA’s Help<br />

system for specific details. To get help while working in the VB Editor window,<br />

press F1 or type your search terms into the Type A Question For Help box in the<br />

menu bar.<br />

This chapter consists of several examples that demonstrate common VBA techniques.<br />

You may be able to use some examples directly, but in most cases, you<br />

must adapt them to your own needs. These examples are organized into the following<br />

categories:<br />

IN THIS CHAPTER<br />

Working with ranges<br />

Working with charts<br />

Modifying properties<br />

VBA speed tips<br />

n<br />

n<br />

n<br />

n<br />

Working with ranges<br />

Working with workbooks<br />

Working with charts<br />

Programming techniques to speed up your VBA code<br />

Working with Ranges<br />

Most of what you do in VBA probably involves worksheet ranges. When you<br />

work with range objects, keep the following points in mind:<br />

n<br />

n<br />

n<br />

Your VBA code doesn’t need to select a range to do something with the<br />

range.<br />

If your code does select a range, its worksheet must be active.<br />

The macro recorder doesn’t always generate the most efficient code.<br />

Often, you can use the recorder to create your macro and then edit the<br />

code to make it more efficient.<br />

757

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!