If you use Excel to model businesses, business processes, or business transactions, this course will change your life. You’ll learn how to create tools for yourself that will amaze even you. Unrestricted use of this material is available in two ways.
To Order On Line
Order "Spreadsheet Models for Managers, on-line edition, one month" by credit card, for USD 69.95 each, using our secure server, and receive download instructions by return email. |
Order "Spreadsheet Models for Managers, on-line edition, three months" by credit card, for USD 199.00 each, using our secure server, and receive download instructions by return email. |
Order "Spreadsheet Models for Managers, downloadable hyperbook edition" by credit card, for USD 199.00 each, using our secure server, and receive download instructions by return email. |
To Order by Mail
Make your check payable to Chaco Canyon Consulting, for the amount indicated:
|
And send it to: Chaco Canyon Consulting 700 Huron Avenue, Suite 19C Cambridge, MA 02138 |
To use the course software you’ll need some other applications, which you very probably already have. By placing your order, you’re confirming that you have the software you need, as described on this site.
We have one demonstration (2007+) for this session: How to Write Function Macros in VBA.
Here are four examples of simple function macros.
The EOQ macro implements the formula for EOQ. You can view the macro source code as follows:
Excel 2007, 2010, and 2013 | Excel 2011 |
The EOQ macro is a simple function macro, the first one in the module. It uses the VBA function Sqr to compute the square root. To find VBA functions, look in the Visual Basic on line help, for the volume called “Visual Basic Language Reference” and, within that, look for “Functions.” The work we’ll do with macros won’t require knowledge of VBA functions.
This macro illustrates how to return objects. As it happens, this macro does nothing. But if you want to return an object, the assignment statement must use “Set”.
The geometric mean of two numbers is the square root of the product of the two numbers. This function macro implements it. Notice the choices of function names and argument names. Names can be any string of alphanumeric characters and underscores, starting with letters. Case doesn’t matter. In our example, we’ve chosen names that are designed to make the macro easy to understand, without the need for extensive commenting. Managers of groups of people who make spreadsheet models should ensure that function and variable names are chosen with these factors in mind.
Here’s an implementation of the depreciation schedule generator that supports the Ripple Principle. It’s analogous to what we did in the examples for Session 8. It uses Caller, a property of the Application object that holds the cell that invoked the function. It also uses Column, a property of a range object. Both of these property invocations illustrate how VBA uses postfix notation to access properties of objects. To test your understanding of Caller, write a worksheet function that returns twice the value of the cell to the right of the caller.
Last Modified: Wednesday, 27-Apr-2016 04:15:26 EDT
We focus on function macros in this course because they’re more likely than command macros to make a real difference in your facility with constructing models. For instance, when your customer wants to see result streams displayed as [Month1, Month2, Month3, Q1 Total, Month4, Month5, Month6, Q2 Total, …], you probably realize that such a layout makes copy/paste and fill very inconvenient. A macro can provide a simple means of producing the preferred layout from a more easily maintained pure month structure. It’s also easy to construct macros for running sums and running differences. Can you think of other applications for function macros that make your models easier to build and maintain?