How to Use Visual Basic With Excel

by Stephanie Ellen
computer image by Ewe Degiampietro from <a href=''></a>

If you are tired of formatting worksheets the same way over and over again, or entering the same formulas repetitively, Excel's Visual Basic for Applications (VBA) was made for you. The programming language, a subset of Visual Basic, can replace those dull tasks with an automated function. The language doesn't even require an additional cost outlay---you may not have noticed it, but the Excel Visual Basic Editor is included with every copy of Excel.

Step 1

Press Alt + F11 to open the Visual Basic editor from Excel.

Step 2

Click "Insert > Module" to open a blank module window.

Step 3

Copy and paste the following code into the blank window: Sub BoldRed() With Selection.Font .ColorIndex = 3 .Bold = True End Sub

Press F5 to run your macro. When you see a macro dialog box, enter the shortcut key you want to access the macro with, then click "Run." Whatever text you have selected will automatically become bold and red. You can use the shortcut key you specified to execute the macro any time you want.


  • The macros you create are named the same thing as the "sub" by default. In the example code, the macro will be called "BoldRed," but you can change the macro name to whatever you want.


Photo Credits

About the Author

Stephanie Ellen teaches mathematics and statistics at the university and college level. She coauthored a statistics textbook published by Houghton-Mifflin. She has been writing professionally since 2008. Ellen holds a Bachelor of Science in health science from State University New York, a master's degree in math education from Jacksonville University and a Master of Arts in creative writing from National University.

More Articles