Skip to Content
Excel VBA Programming For Dummies, 6th Edition
book

Excel VBA Programming For Dummies, 6th Edition

by Dick Kusleika
February 2022
Beginner to intermediate content levelBeginner to intermediate
432 pages
9h 21m
English
For Dummies
Content preview from Excel VBA Programming For Dummies, 6th Edition

Chapter 24

Ten VBA Do’s and Don’ts

IN THIS CHAPTER

Bullet Discovering five VBA-related things you should do

Bullet Discovering five VBA-related things you should not do

If you're reading this final chapter, you’ve probably read most of the content of this book and are familiar with Excel VBA. Or maybe you just skipped to the end because you wanted to see whether the butler actually did it.

This chapter gives you some advice you should take into account when you start developing your own VBA solutions. Following these guidelines is no panacea to keep you out of (programming) trouble, but following them can help you avoid pitfalls that others have stumbled over.

Do Declare All Variables

How convenient it is: Simply start typing your VBA code without having to go through the tedious chore of declaring each and every variable you want to use. Although Excel allows you to use undeclared variables, doing so is simply asking for trouble.

The first commandment of VBA programming should be this:

Thou shalt declare every variable.

To force yourself to obey that commandment, add an “Option Explicit” statement at the top of your modules. That way, your code won’t even run if it includes one or more undeclared variables. Not declaring all variables has only one advantage: You save a few seconds. But ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel VBA Programming For Dummies, 5th Edition

Excel VBA Programming For Dummies, 5th Edition

Michael Alexander, John Walkenbach

Publisher Resources

ISBN: 9781119843078Purchase Link