Accessing Worksheet Functions

VBA has dozens of functions of its own, but its collection is downright meager compared to the hundreds of worksheet functions available with Excel. If you need to access one of these worksheet functions, VBA makes them available via a property of the Application object called WorksheetFunction. Each function works exactly as it does on a work-sheet—the only difference being that you have to append Application. to the name of the function.

For example, to run the SUM() worksheet function on the range named Sales and store the result in a variable named totalSales, you'd use the following statement:

totalSales = Application.WorksheetFunction.Sum(Range("Sales"))

0 0

Post a comment