#Visual basic for excel learn how to#
We’ll show you how to build those forms, visually, with a drag-and-drop editor.Įrror Handling. The power of VBA becomes clear when you can ask the person looking at your spreadsheet to click on a button, have a nice-looking form pop up, and let them type in some data or choose options from a dropdown box - and then have your custom VBA code process that data and make intelligent updates to the underlying spreadsheet. We’ll cover the basics (no pun intended) of coding: grabbing onto Excel cells and changing their properties, getting input from the user, tracking changeable values in “variables,” executing different chunks of code depending on if-this-then-that decisions, and repeating a chunk of code multiple times. Microsoft has gone out of its way to make VBA as simple as possible. Don’t worry if you haven’t written code before. It has features for organizing your code, giving you hints about what the functions should look like, and debugging your program while watching it run, step-by-step. Microsoft provides a separate free app to help you write code, the “Visual Basic Code Editor.” You can launch it right from Excel. Automating repetitive tasks is another popular use of VBA. You can also change their properties: sizes, colors, fonts, etc. You can write VBA code to grab parts of Excel (cells, rows, menus, etc.) - and even data from the web - and programmatically change their values. VBA is a programming language built right into Excel and other MS Office applications. There’s no feature for that in Excel! That’s where Visual Basic for Applications (“VBA”) comes in. What if, for example, you had a worksheet with 20 cities and you wanted to put their current temperatures in each adjacent cell. Sooner or later, every Excel user runs into a problem that can’t be solved with a built-in function or feature.