You are on page 1of 2

Crystal Ball Functions

Some Crystal Ball functions can be used directly from within Excel.
Source: Developer Kit for Crystal Ball 2000 and CB Predictor, Decisioneering Inc., 1999.

Sometimes is it useful to embed some functions directly into a worksheet; for example, to
automatically extract summary statistics and/or percentiles from a simulation. These can be
specially formatted for a user, who does not have to know anything about the CB interface.

All of these functions (and others) can be accessed from the function wizard in Excel, or typed in
like any other Excel function (of course, the CB add-in must be loaded first). In the function wizard,
the CB functions are in the “Crystal Ball” category.

Probability Functions for each of the probability distributions included in CB. See
CB.xxx (distribution parameters)
Distributions list in Table 3.1 (page 88) of Evans & Olson book.
Returns descriptive statistics for the specified forecast cell.
ForeReference must point to a defined forecast cell (if not, #VALUE
is displayed). Index is a number between 1 and 13. Before a
simulation is run, or after resetting, the results are shown as zeroes.
The values of Index return the following values:
1: number of trials
2: mean
3: median
CB.GetForeStatFN 4: mode
(ForeReference, Index) 5: standard deviation
6: variance
Simulation 7: skewness
Results 8: kurtosis
9: coefficient of variability
10: minimum
11: maximum
12: range (max-min)
13: standard error
CB.GetForePercentFN(ForeRefere Returns value of a forecast for a specified percentile (cumulative
nce, Percent) probability). The percentile is a number from 0 to 100.
CB.GetCertaintyFN(ForeReferenc Returns the certainty level (cumulative probability) for a given value
e, Value) of a forecast.
CB.IterationsFN() Returns the number of iterations so far in a simulation run.
CB.GetAssumFN (AssumRef,
Returns information about assumption cells.
Index)
CB.GetAssumPercentFN(AssumR Returns percentile of an assumption cell, based on the assumption
eference, Percent) cell’s distribution. Similar to GetForePercentFN for a forecast cell.
Model CB.GetDecVarFN (DecVarRef,
Returns information about decision variable cells.
Information Index)
CB.GetForeFN (ForeRef, Index) Returns information about forecast cells.
Returns the correlation coefficient between two assumption cells (2nd
CB.GetCorrelationFN(AssumRef,
assumption cell specified by column number and row number, for
Column, Row)
some odd reason).
Crystal Ball
CB.GetVersionFN() Returns CB version information
Information

CB_Functions.doc, 5/31/2004, 12:01 AM Created by Roger Grinde Page 1 of 2


Using Basic Crystal Ball Macros

Crystal Ball can be completely controlled from Visual Basic for Applications (VBA), which resides “behind”
all of the Microsoft Office applications (and some non-Microsoft applications). “Intense” VBA programming
is beyond the scope of this handout, but demonstrating the potential utility is fairly straightforward.
Following the instructions in this handout will allow you to run a simulation from a button, and to generate a
report once the simulation is run. Interested users should consult the CB Developers Manual.

1. Create the simulation model in Excel/Crystal Ball.


2. Enter the Visual Basic Editor (Tools…Macro…Visual Basic Editor, or Alt-F11).
3. Find the current file on the left pane; select it.
4. From the Insert menu, choose Insert Module. “Modules” are where VBA code is written or recorded.
5. From the Tools menu, choose References. From the resulting list, put a check beside cb.xla. Doing this
allows VBA to find the relevant Crystal Ball routines you will use later.
6. Activate the Module created in step 4 (if it isn’t already). There should be a blank window in the right
pane.
7. Type the code shown below into the Module window. The RunSimulation routine resets any existing
simulation (without asking the user to confirm it), and runs the currently-defined simulation for 500
iterations (see #11 below for a more flexible approach). The CreateReport routine does just that, again
without asking the user to confirm choices. If it is desired that the user be able to confirm these things,
leave off the “ND” from the routines being called.
8. Close the Visual Basic Editor (no need to save, because this code is actually saved within your Excel
workbook).
9. You may run these new routines by going to Tools…Macro…Macros in Excel. RunSimulation and
CreateReport should be in the list.
10. You can also assign these routines to buttons or toolbars. To make a button and assign a routine to it, go
to View…Toolbars…Forms. Choose the icon looking like a button, drag in the spreadsheet to size the
button, and Excel automatically prompts you to assign a macro to it. Now you can click within the button
and name it how you choose. If you ever want to resize or rename the text in the button, right click it first
(left-clicking runs the routine!).
11. If you want to allow the user to specify the number of iterations, but still make it easy to run the
simulation from a button, you can have the user type in the number of iterations in a worksheet cell. The
RunSimulation routine can be modified to read the number of iterations from this cell. Suppose you store
the number of iterations in cell A1. Then change the CB.Simulation line in the RunSimulation routine to:
CB.Simulation Range(“A1”).Value
12. Many other CB routines exist which can be accessed using VBA. Essentially, anything you can do
interactively with CB can also be done through VBA. The Developer’s Manual contains details on how
to accomplish this. A number of good books on VBA itself are available for those interested.

Code for the VBA routines

Sub RunSimulation()
CB.ResetND
CB.Simulation 500
End Sub

Sub CreateReport()
CB.CreateRptND CBRptOK
End Sub

CB_Functions.doc, 5/31/2004, 12:01 AM Created by Roger Grinde Page 2 of 2

You might also like