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 Distributions

CB.xxx (distribution parameters)

CB.GetForeStatFN (ForeReference, Index) Simulation Results

Model Information

CB.GetForePercentFN(ForeRefere nce, Percent) CB.GetCertaintyFN(ForeReferenc e, Value) CB.IterationsFN() CB.GetAssumFN (AssumRef, Index) CB.GetAssumPercentFN(AssumR eference, Percent) CB.GetDecVarFN (DecVarRef, Index) CB.GetForeFN (ForeRef, Index) CB.GetCorrelationFN(AssumRef, Column, Row)

Functions for each of the probability distributions included in CB. See 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 4: mode 5: standard deviation 6: variance 7: skewness 8: kurtosis 9: coefficient of variability 10: minimum 11: maximum 12: range (max-min) 13: standard error Returns value of a forecast for a specified percentile (cumulative probability). The percentile is a number from 0 to 100. Returns the certainty level (cumulative probability) for a given value of a forecast. Returns the number of iterations so far in a simulation run. Returns information about assumption cells. Returns percentile of an assumption cell, based on the assumption cells distribution. Similar to GetForePercentFN for a forecast cell. Returns information about decision variable cells. Returns information about forecast cells. Returns the correlation coefficient between two assumption cells (2nd assumption cell specified by column number and row number, for some odd reason). Returns CB version information

Crystal Ball Information

CB.GetVersionFN()

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. 2. 3. 4. 5. 6. 7. Create the simulation model in Excel/Crystal Ball. Enter the Visual Basic Editor (ToolsMacroVisual Basic Editor, or Alt-F11). Find the current file on the left pane; select it. From the Insert menu, choose Insert Module. Modules are where VBA code is written or recorded. 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. Activate the Module created in step 4 (if it isnt already). There should be a blank window in the right pane. 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. Close the Visual Basic Editor (no need to save, because this code is actually saved within your Excel workbook). You may run these new routines by going to ToolsMacroMacros in Excel. RunSimulation and CreateReport should be in the list. You can also assign these routines to buttons or toolbars. To make a button and assign a routine to it, go to ViewToolbarsForms. 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!). 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 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 Developers Manual contains details on how to accomplish this. A number of good books on VBA itself are available for those interested.

8. 9. 10.

11.

12.

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