Sub topic 8
Naming the Selector and Index for Readable Formulas
This chapter assumes you have built the pieces from the earlier chapters. These are a selector cell with a dropdown (C3), a MATCH formula that turns the scenario name into an index (C4), and a live case row that uses CHOOSE. It also assumes you know absolute references ($C$3) and can read a formula such as =CHOOSE($C$4, E12, F12, G12).
That formula works. The weak point is $C$4. Six months from now, you or a colleague will have to go to that cell to find out what it holds. A named range fixes this. It is a label that you attach to a cell or a block of cells, and you can then use the label in formulas instead of the address.
Why names help in a scenario model
The selector and the index are referenced from many places. Every live case row points at the index, and the integrity checks point at both cells. A scenario model can easily have 30 or more formulas that read $C$4.
Compare the two versions:
=CHOOSE($C$4, E12, F12, G12)
=CHOOSE(Scen_Index, E12, F12, G12)The second version tells the reader what drives the choice. Names also help in three other ways:
- Safer edits. A name points to the cell wherever it moves. If you insert a row above the selector, the name still refers to the right cell, as an ordinary reference would. A name also keeps a formula readable when you copy it to another sheet, where
$C$4would silently point at the wrong place. - Easier auditing. With Name Manager, you can see every important cell in the model in one list.
- Fewer typing mistakes. A misspelled name returns
#NAME?straight away. A mistyped address such as$C$5returns a plausible number from the wrong cell.
Names do not make the model faster or more accurate. They make it easier to read and to check.
Rules for valid names
Excel rejects some names, and the rules matter because the failures can be confusing.
| Rule | Valid example | Invalid example | Why |
|---|---|---|---|
| Starts with a letter, underscore or backslash | `Scen_Index` | `1_Scenario` | A leading digit is not allowed. |
| No spaces | `Scen_Selected` | `Scen Selected` | Spaces separate tokens in formulas. Use an underscore or a period. |
| Must not look like a cell address | `Scen_List` | `SC1`, `R1C1` | Excel reads `SC1` as column SC, row 1. |
| Not a single `C` or `R` | `Case_Idx` | `C`, `R` | These letters are reserved for the R1C1 notation. |
| Up to 255 characters | `Scen_Selected` | A 300-character name | Keep names short in practice. |
Names are not case sensitive, so scen_index and Scen_Index are the same name. Pick one style and keep it. A common convention is a short prefix that groups related names, so Scen_Selected, Scen_Index and Scen_List sort together in Name Manager and appear together in the autocomplete list when you type Scen.
Creating the three names
Assume the selector sits on a sheet called Inputs, with this layout from the earlier chapters:
- C3 holds the selected scenario name (the dropdown).
- C4 holds the index returned by
MATCH. - B5:B7 holds the list
Base,Upside,Downside.
Define the three names like this:
Name: Scen_Selected
Refers to: =Inputs!$C$3
Name: Scen_Index
Refers to: =Inputs!$C$4
Name: Scen_List
Refers to: =Inputs!$B$5:$B$7There are three ways to create a name in Excel:
- Name Box. Select the cell, click the Name Box left of the formula bar, type the name and press Enter. This is the fastest way for a single cell.
- Define Name. Go to Formulas, then Define Name. This dialog lets you choose the scope and add a comment.
- Create from Selection. Select a label and its cell, then press Ctrl+Shift+F3. Excel uses the label text as the name. Take care with this one, because Excel replaces spaces with underscores and may produce names you did not plan.
Name Manager (Ctrl+F3) lists all the names, their values and what they refer to. Use it to edit or delete names.
In Google Sheets, use Data, then Named ranges. The idea is the same, but all names are workbook-wide.
Always use absolute references in the definition
A name should refer to $C$3, not C3. A name defined with a relative reference is interpreted relative to the cell that is active when you define it. When you use it in another cell, it points to a different cell. This is a real feature, but it is almost never what you want for a selector. If a name returns a value from the wrong cell, check the Refers to box in Name Manager first.
Using the names in each step of the switch
Now replace the addresses in every step of the switch.
The dropdown. Open the data validation dialog on the selector cell, choose a list, and enter the name as the source:
Data validation (Allow: List)
Source: =Scen_ListIf you later add a fourth scenario, you change one definition (see the section on growing the list below) and the dropdown follows.
The index. In C4, write the MATCH formula with names:
=MATCH(Scen_Selected, Scen_List, 0)This formula reads almost as a sentence: find the selected scenario in the scenario list, exact match.
The live case row. The CHOOSE formula now reads:
=CHOOSE(Scen_Index, E12, F12, G12)You may also name the output of the live case, for example Rev_Growth for the live revenue growth cell, so that calculation sheets read =Prior_Revenue * (1 + Rev_Growth). Do this only for drivers that many formulas use. Giving a name to every cell in the model creates a long list that nobody can read.
The diagram shows how the names connect the steps.
Scope: workbook or sheet
Every name has a scope, which is the area where it can be used without a sheet prefix.
- Workbook scope is the default. The name works on every sheet. Use it for
Scen_Selected,Scen_IndexandScen_List, because the whole model depends on them. - Sheet scope limits the name to one sheet. Two sheets can each have a sheet-scoped name
Total. From other sheets you must writeInputs!Total.
The scenario switch needs workbook scope. A gotcha appears when someone copies a sheet that contains workbook-scoped names. Excel copies the names as sheet-scoped names on the new sheet, and then the new sheet's formulas use the copy, not the original. The copy can keep an old index while the model switches. If you copy sheets in a model, open Name Manager afterwards and look for duplicate names with different scopes.
Names that grow with the list
If you add a fourth scenario in B8, the name Scen_List still ends at B7, so the dropdown does not show it. There are three ways to deal with this:
- Insert inside the range. Insert a new row between B5 and B7, then enter the scenario there. The name expands automatically.
- Use an Excel table. Put the scenario names in a table and point the name at the table column. The name grows with the table.
- Use a dynamic formula. In current versions of Excel,
=Inputs!$B$5:INDEX(Inputs!$B:$B, COUNTA(Inputs!$B:$B))defines a range whose end depends on the count of entries. This works if column B contains only the scenario names. AvoidOFFSETfor this purpose, because it is volatile and recalculates every time anything changes.
A new scenario also needs a new argument in every CHOOSE formula. This is a limit of CHOOSE, and a later chapter compares it with INDEX.
Common errors with names
| Symptom | Likely cause | Fix |
|---|---|---|
| `#NAME?` in a formula | The name is misspelled, deleted, or defined in another scope. | Open Name Manager, confirm the name and its scope, then correct the formula. |
| Dropdown shows no items | The name `Scen_List` refers to an empty or wrong range. | Check the Refers to box in Name Manager. |
| `#REF!` inside a name | The cell or sheet it pointed to was deleted. | Redefine the name. Do not delete cells that names refer to. |
| A name returns a different cell on each row | The definition used a relative reference. | Redefine with `$` signs. |
| Two names with the same label | A sheet copy duplicated workbook names as sheet-scoped names. | Delete the duplicates, keep the workbook-scoped name. |
| `Scen_Index` returns `#N/A` | The selected name is not in the list, for example after a typo in the list. | Reselect from the dropdown and check that `Scen_List` holds the exact spelling. |
Mixing names and addresses
After you introduce names, search the workbook for the old addresses. If $C$4 still appears in some formulas, the model works until someone moves the index. The name follows the move, and so does the address, but a person reading the formulas cannot tell they mean the same thing. Use Find (Ctrl+F) with the option "Look in: Formulas" and search for $C$4. Replace each result by the name. A quick test also helps. Change the selector, and confirm that every row you expect to change has changed.
Names also have a cost. A reader who does not know the model cannot see where Scen_Index lives by looking at a formula. Solve this by listing the names on the assumptions sheet, with the cell, a short description and the current value. Name Manager can show the list, and Formulas, then Use in Formula, then Paste Names, pastes a full list into the sheet. Paste it into a documentation block and update it when you add names.
Summary of the practice
- Name the three cells that drive the switch: the selected scenario, the index and the scenario list.
- Use workbook scope and absolute references.
- Use the names in the dropdown source, in
MATCHand inCHOOSE. - Name only the drivers that many formulas use.
- Check Name Manager after copying sheets, deleting cells or adding scenarios.
Exercise
In your model, Scen_Index is defined as =Inputs!C4 (no dollar signs) while cell C20 on the Inputs sheet is active. A colleague uses =CHOOSE(Scen_Index, E12, F12, G12) in a cell on row 30 and gets a number that does not match the selector. What is the problem, and how do you fix it?
Show answer
Without dollar signs, the name is a relative reference. Excel interprets it relative to the active cell when the name was defined, so from another cell it points at a different cell than C4. Open Name Manager (Ctrl+F3), edit Scen_Index so that it refers to =Inputs!$C$4, and check the result.
Exercise
You add a fourth scenario, "Stress", in B8, directly below the list that Scen_List covers (B5:B7). The dropdown does not show "Stress" and MATCH returns #N/A when you type it. Give two ways to fix this, and say what else you must update.
Show answer
Either extend the name to =Inputs!$B$5:$B$8 in Name Manager, or insert the new row inside the existing range (or use a table or dynamic range) so that the name grows with the list. You must also add a fourth argument to every CHOOSE formula (and a fourth assumption column), because CHOOSE with three values returns #VALUE! for index 4. The integrity check that tests the index against 3 also needs a new upper bound.