Events

Running the VBA program is most often initiated by an event. Events can be on the document-level (eg Open, Activate), worksheet (eg Calculate, Change), charts, applications, forms … The event that starts the subroutine is mainly a click on a button or object, object focus or change the content of the object. Some events are executed automatically after opening an existing or creating a new document …

VBA filtering

Filters are a very useful functionality that enables us to filter content in the table or area above which the autofilter was previously used based on a given criterion. This can be accomplished in many ways, but there is always an event that we are launching to perform the action. In this “recipe” you will learn how to filter the table with the help of previously prepared, combo lists.

Coloring the content

Colors help us to emphasize the contents of the worksheet, and the VBA allows you to do so through the code. You can change the colors of the font, background or cell border. This can be done in several ways: by specifying a VBA constant representing color, by typing a color code or by specifying a RGB color combination using the same name function …

VBA and comments

Comments in Excel are a convenient way to leave notes about the results of the calculations you made or otherwise explain your work within the worksheet. VBA allows you to easily add and delete comments. The following text will describe how to create programs by which you add or delete comments from within an active cell.

VBA and SQL Server

In several previous “recipes” I wrote about how to connect to Microsoft SQL Server from Excel in order to retrieve data to a worksheet. These were all “innocent” operations, since you could only read the data from the database, not to change them. Sometimes it is necessary to create a program that performs more complex manipulation over the database by running appropriate SQL query, which will be discussed in the text that follows.