Worksheet Functions

Worksheet functions are an area often overlooked by the Microsoft Excel VBA developer. Microsoft Excel provides over 170 spreadsheet-specific functions that can be accessed from your VBA code. You'll find mathematical, financial, lookup, database, and many other function categories that can speed your worksheet-specific operations. While these functions were originally designed for use in a worksheet setting, many of them are excellent additions to the VBA developer's toolbox.

Referencing functions such as MATCH, VLOOKUP, HLOOKUP, and INDEX, combined with other worksheet functions such as COUNT, COUNTA, MIN, MAX, and SUM, can create very powerful tools for referencing a spreadsheet. Remember that VBA is a generic language that works across the Microsoft Office family (and beyond), but these worksheet functions are specific to Microsoft Excel.

Additionally, worksheet functions that operate on ranges in Microsoft Excel worksheets can be used with VBA arrays. Functions such as MATCH, SUBSTITUTE, INDEX, ISBLANK, VLOOKUP, and SUM can be used in this manner. There is some small overhead compared with VBA functions, but many of the worksheet functions have no VBA counterpart.

In previous versions of Microsoft Excel, worksheet functions were contained in the Application object. In Microsoft Excel 97, a new object called the WorksheetFunction object is used as a container for all the worksheet functions that can be called from Visual Basic.

Online Help has an excellent section, called "Using Microsoft Excel, Worksheet Functions in Visual Basic," which provides details on using these functions. It also has a complete list of functions available by using the WorksheetFunction object. Be sure to skim this list a few times and familiarize yourself with these powerful functions.