Written by Allen Wyatt (last updated September 12, 2020)**This tip applies to** Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365

Joran is doing a comparison of 13 different models of student financial aid (by provinces/territories in Canada). Each model has its own worksheet which feeds into a summary page. Joran would like to be able to compare the complexity of each individual worksheet (province/territory) in a concrete way. When using the 'Evaluate Formula' tool, each step of a given formula is isolated. He would like to know if there is a way to count the number of evaluation 'steps' contained in an entire spreadsheet. This would provide Joran with a somewhat objective measure that would be comparable across the workbook.

Unfortunately, it appears that Excel doesn't make the 'Evaluate Formula' tool available, as an object, within VBA. That means that to evaluate a worksheet in this manner would require developing a macro to look through all the cells, pull out formulas, and count the "functional phrases" in each formula. This could become rather complex in short order.

Even though this could be done (complexity aside), it may not produce the desired results. As an example, consider the following formula:

=A1+A2+A3

This formula has either two or three evaluations, depending on how you count evaluations. Now consider the following formula:

=SUM(A1:A3)

This formula is functionally equivalent to the previous one, but it requires only one evaluation. Neither formula is more complex than the other, but if you only count evaluations, the first would show as two or three times as complex as the second. Some functions, even though counted as a single evaluation, are much more complex than simple addition and this is also ignored when simply counting phrases.

Further, if your formulas include any type of decision-making structure (typically using the IF function), then the complexity of the formula isn't directly tied to the number of phrases or evaluations in the formula. The reason is because what Excel actually calculates is determined at the time of calculation based on the conditions present at that time.

Recognizing that counting phrases isn't the best way to determine model complexity naturally leads to the question of how one can make the determination. What can be examined within a worksheet to objectively determine complexity. There is no easy way to make such a determination. This is explained, in part, by Steve, an ExcelTips subscriber who is a PhD development chemist. As part of his work he designs experiments and analyzes them to create logistical and business models. Here's his comments:

===[begin Steve's comments on model complexity]===

A simpler evaluation of the complexity of the model, is the number of terms used in the model to get the results. When evaluating models, in my experience I have found that you want to find a balance of simple vs results. One adds elements that provide real substance to the results and eliminates those that do not.

A measure of fit used in models is termed the *coefficient of determination* (also known as R^2, R-squared). It is a measure of how well the model fits the actual data. It is the ratio of the "sum of squares" of the regression, meaning the square of the value of the model vs the actual for each individual value, divided by the sum of squares total, meaning the square of differences of each point to the mean of the points.

But as one adds complexity (by adding additional terms) the R^2 get higher as the degrees of freedom go down. An adjusted R^2 is good comparison:

Adjusted R^2 = 1 - (1-R^2) * (n-1) / (n-k-1)

where R^2 was as described above, n is the number of points, and k is the number of terms used in the model.

Typically, one strives for the maximum adjusted R^2.

===[end Steve's comments on model complexity]===

Unless one is highly conversant in statistical methods and math, it is easy to get lost in the details of determining complexity in this manner.

If going down such a trail is not to your liking (or your training), then there is another way of determining complexity: How long does it take to arrive at a result using each model? If you put each model's worksheet into its own workbook, you can use a macro to measure how long it takes to perform a recalculation on the workbook. Since Excel uses the same internal methods to perform recalculation on each workbook, you can easily compare timing on each of the workbooks. For a general, seat-of-the-pants indication of complexity, the workbook that takes the longest to recalculate is the one that is most complex.

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (13096) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

**Create Custom Apps with VBA!** Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out *Mastering VBA for Office 2013* today!

Need to make a copy of one of your worksheets? Excel provides a few different ways you can accomplish the task.

Discover MoreExcel places a limit on how many characters you can use in a worksheet name. This tip discusses that limit and provides ...

Discover MoreYour workbooks can contain many, many worksheets. Which of those worksheets are the largest, however? Here's some ideas ...

Discover More**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

2020-09-15 14:55:35

Ronmio

=A1+A2+A3

=SUM(A1:A3)

That's only true if all the cells contain values. If some of the cells could legitimately contain text then =A1+A2+A3 would produce a #VALUE! error. To make that first formula functionally equivalent to the second one, it would need to be something like ...

=IF(AND(ISTEXT(A1),ISTEXT(A2),ISTEXT(A3)),"no values found", IF(AND(ISNUMBER(A1),ISTEXT(A2),ISNUMBER(A3)),A1+A3,

IF(AND(ISNUMBER(LA1),ISNU ...

So, in order to handle all the permutations of text and values, it could end up being a very long, complex formula.

The takeaway is that the SUM function tolerates text but standard math formulas with operands do not. But that doesn't mean you always want to use the SUM function. Having a formula catch text-value errors (e.g., the letter O instead of the number 0 in a value) where there should only be values could be critical. That's when you would want to use a simple math formulas with operands because it will make you aware of the text error.

Got a version of Excel that uses the
ribbon interface (Excel 2007 or later)?
**This site is for you!** If you
use an earlier version of Excel, visit
our *ExcelTips* site focusing on the menu interface.

**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

Copyright © 2024 Sharon Parq Associates, Inc.

## Comments