The On Error Statement: To Use or Not To Use

Managing coding errors can be a time consuming and complex task in VBA. Unlike many modern programming languages, VBA lacks native functions that help avoid common errors, sometimes requiring the use of the On Error statement. While the On Error statement can seemingly make a procedure work, it does not …

VLOOKUP… to the Left!

Have you ever been attempted to use VLOOKUP in a large data set, only to realize the data you’re seeking is to the left of the lookup column? Sure, you could cut/paste the lookup column the left of the table, but that might interfere with other parts of the dataset. …

Building User-Defined Functions in VBA

While subroutines can be called within other subroutines, their environments are generally segregated — a subroutine cannot directly provide any information to another subroutine. Using functions, however, permits the transfer of a value, array, or object from one procedure to another.

Creating and Using Enumerations in VBA

Enumerations are data structures useful for grouping a elements which can be (or need to be) be associated with numeric values. Examples of useful enumerations are products with product IDs, or working with date values, such as months 1 through 12. Many developers also use enumerations to manage events, such …

Creating and Using Constants in VBA

A constant is a data structure used to store a specific static value that must be retained through the entire execution of a script. While constants may seem somewhat restrictive, they provide an advantage with memory usage and script readability.

Nested Loops – Looping Within Loops

While stand-alone loops will accomplish many tasks that require basic iteration, loops can be nested within other loops. In Excel, nested loops provide robust functionality to complete a number of tasks, such as filling out spreadsheet data, creating multidimensional arrays, or formatting cells.

Using a Do Loop to Iterate Through Spreadsheet Data

Do Loops are an effective means of iterating through a set of data where the number of iterations is not known. Given the versatility and easy for adding and removing data on an Excel spreadsheet, a Do Loop is an extremely valuable tool when used effectively in VBA.

Logical Operators for Conditional Statements in VBA

While the previous post explained how to use conditionals to execute specific blocks of code, the conditions were relatively strict, relying on single variables or liberal values. This post provides an overview of how to incorporate logical operators into conditional statements, permitting much needed flexibility with complex testing.

Using Conditional Statements in VBA

Previous posts on the Getting Started with VBA Series have focused on how to both extract information from cells on the spreadsheet, and create information in VBA with variables. While these may meet the needs of some simple programs, conditional statements open the door to creating responsive programs.