# Excel add in development in C++ Aplications in finance - Dalton S.

ISBN 0-470-02469-0

**Download**(direct link)

**:**

**23**> 24 25 26 27 28 29 .. 168 >> Next

• Fixed input (constant) data to be changed only rarely, representing assumptions, numerical coefficients, data from a particular publication or source that must be reproduced faithfully, etc.

• Static data, typically labels, that make the spreadsheet readable and navigable and provide users with help, instructions and information about the contents and algorithms.

• Calculated data resulting from the action of a function or command.

There might also be cells containing functions whose values are largely irrelevant but that perform some useful action when they are re-evaluated, for example, writing to a log file when something changes.

Here are some guidelines for creating spreadsheets that are easy to navigate, maintain and understand:

1. Provide version and revision data (including name and contact details of the author(s) if the workbook is to be used by others).

2. Group related assumptions and magic numbers together and provide clear comments with references to other documents if necessary.

3. Group external links together, especially where they come from the same source, and make it clear that they are external with comments.

4. Avoid too much complexity on a single worksheet. Where a worksheet is becoming over-complex, split it in two being careful to make the split in such a way that cross-worksheet links are minimised and that these links are clearly commented in both sheets.

5. Avoid too much data on a single worksheet. Too much may be difficult to define - a very large but simple table would be fine, but 100 small clusters of only loosely related data and formulae are probably not.

6. Avoid excessive and unnecessary formula repetition, and repetition of expressions within a single formula.

Excel Functionality 37

7. Avoid over-complex formulae. Even where repetition within the formula isn’t a concern, consider breaking large formulae down into several stages. Large and complex formulae are not only difficult to read and understand later, but make spreadsheets harder to debug.

8. Use named ranges. This not only makes formulae that reference the data more readable and easier to understand but also makes accessing the data in VB or a C/C++ add-in easier and the resulting code independent of certain spreadsheet changes.

9. Use formatting (fonts, borders, shading and text colours) not only to clarify the readability, but also to make a consistent distinction between, say, variable inputs, external dynamic data and ‘static’ assumption data.

10. Use hyperlinks (press Ctrl-K) to navigate from one part of a large book to another.

2.15.4 Formula repetition

Excel is a faithful servant. It will do what you tell it to do without question and, more significantly, without optimisation. A cell formula such as

=IF(VLOOKUP(W5,B3:B10,1)<SUM(A3:A10),VLOOKUP(W5,B3:B10,1)+SUM(A3:A10),

VLOOKUP(W5,B3:B10,1)-SUM(A3:A10))

will cause Excel to evaluate the VLOOKUP() and SUM() functions twice each. It has no ability to see that the same result is going to be used several times. (You can easily verify this kind of behaviour using a VB macro such as NumCa11s_1() listed in section 2.11.1 on page 25). The obvious solution is to split the formula into 3 cells, the first containing VLOOKUP(), the second containing SUM() and the third containing IF() with references to the other two cells.

Repetitions may not be so obvious as this and do not all need to be removed. Sometimes the action of a fairly complex formula is clearer to see when it contains simple repetitions rather than references to cells somewhere far away in the workbook.

Generally speaking, trying to do things in a minimum number of cells can lead to over-complex formulae that are difficult to debug and can lead to calculation repetition. You should err on the side of using more cells, not fewer. Where this interferes with the view you are trying to create for the user (or yourself), use the row/column hide feature or the Data/Group and Outline/Group feature to conceal the interim calculations, or move the interim calculations to another part of the same worksheet.

2.15.5 Efficient lookups: MATCH(), INDEX() and OFFSET() versus VLOOKUP()

One of the most commonly used and useful features of spreadsheets is the lookup. For the basics of what a lookup is, how it works and the variations read Excel’s help. In using lookups it is important to understand the relative costs, in terms of recalculation time, of the various strategies for pulling values out of large tables of data.

Tables of data usually stretch down rather than across. We think in terms of adding lines at the bottom of a table of data rather than adding columns to the right. We read documents line-by-line, and so on. This bias is, of course, reflected in the fact that Excel has 256 times as many rows than columns. Consequently, most lookup operations involve searching a vertical column of data, typically using VLOOKUP(). However, it is easy to create situations where the use of this function becomes very inefficient.

**23**> 24 25 26 27 28 29 .. 168 >> Next