Background:
VBA for Excel has once again provided the opportunity to demonstrate some basic lean tenets. The methods used to produce the required product or solution can yield significant savings in time and ultimately money. The current practice is not necessarily the best practice in your industry. In manufacturing, trivial or minute differences in methods deployed become more apparent during mass production or as volume and demand increases. The same is true for software solutions and both are subject to continual improvement and the relentless pursuit to eliminate waste.
Using Excel to demonstrate certain aspects of Lean is ideal. Numbers are the raw materials and formulas represent the processes or methods to produce the final solution (or product). Secondly, most businesses are using Excel to manage many of their daily tasks. Any extended learning can only help users to better understand the Excel environment.
The Model:
We recently created a perpetual Holiday calendar for one of our applications and needed an algorithm or procedure to calculate the date for Easter Sunday and Good Friday. We adopted an algorithm found on Wikipedia at http://en.wikipedia.org/wiki/Computus that produces the correct date for Easter Sunday.
In our search for the Easter Algorithm, we found another algorithm that uses a different method of calculation and provides the correct results too. Pleased to have two working solutions, we initially did not spend too much time thinking about the differences between them. If both routines produce the same results then we should choose the one with the faster execution time. We performed a simple time study to determine the most efficient formula. For a single calculation, or iteration, the time differences are virtually negligible; however, when subjected to 5,000,000 iterations the time differences were significant.
This number of cycles may seem grossly overstated, however, when we consider how many automobiles and components are produced each year then 5,000,000 approaches only a fraction of the total volume. Taken further, Excel performs thousands of calculations a day and perhaps even as many more times this rate as numbers or data are entered on a spreadsheet. When we consider the number “calculations” performed at any given moment, the number quickly grows beyond comprehension.
Testing:
As a relatively new student to John Walkenbach’s book, “Excel 2003 Power Programming with VBA“, speed of execution, efficiency, and “Declaring your Variables” have entered into our world of Lean. We originally created two (2) routines called EasterDay and EasterDate. We then created a simple procedure to run each function through 5,000,000 cycles. Again, this may sound like a lot of iterations but computers work at remarkable speeds and we wanted enough resolution to discern any time differences between the routines.
The difference in the time required to execute 5,000,000 cycles by each of the routines was surprising. We recorded the test times (measured in seconds) for three separate studies as follows:
 Original EasterDay: 31.34, 32.69, 30.94
 Original EasterDate: 22.17, 22.28, 22.25
The differences between the two methods ranged from 9.17 seconds to 8.69 seconds. Expressed in different terms, the duration of the EasterDay routine is 1.39 to 1.46 times longer than EasterDate. Clearly the original EasterDate function has the better execution speed. What we perceive as virtually identical systems or processes at low volumes can yield significant differences that are often only revealed or discovered by increased volume or the passage of time.
In the Canadian automotive industry there are at least 5 major OEM manufacturers (Toyota, Honda, Ford, GM, and Chrysler), each producing millions of vehicles a year. All appear to produce similar products and perform similar tasks; however, the performance ratios for each of these companies are starkly different. We recognize Toyota as the high velocity, lean, front running company. We contend that Toyota’s success is partly driven by the inherent attention to detail of processes and product lines at all levels of the company.
Improvements
We decided to revisit the Easter Day calculations or procedures to see what could be done to improve the execution speed. We created a new procedure called “EasterSunday” using the original EasterDay procedure as our base line. Note that the original Wikipedia code was only slightly modified to work in VBA for Excel. To adapt the original Wikipedia procedure to Excel, we replaced the FLOOR function with the INT function in VBA. Otherwise, the procedure is presented without further revision.
To create the final EasterSunday procedure, we made two revisions to the original code without changing the algorithm structure or the essence of the formulas themselves. The changes resulted in significant performance improvements as summarized as follows:
 For integer division, we replaced the INT (n / d) statements with a less commonly used (or known) “\” integer division operator. In other words, we used “n \ d” in place of “INT( n / d)” wherever an integer result is required. This change alone resulted in a gain of 11 seconds. One word of caution if you plan to use the “\” division operator: The “n” and “d” are converted to integers before doing the division.
 We declared each of the variables used in the subsequent formulas and gained yet another remarkable 11 seconds. Although John Walkenbach and certainly many other authors stress declaring variables, it is surprising to see very few published VBA procedures that actually put this to practice.
Results:
The results of our Time Tests appear in the table below. Note that we ran several timed iterations for each change knowing that some variations in process time can occur.
EasterDay = 31.34375  Original Code uses INT( n / d ) to convert Division Results 
EasterSunday = 20.828125  1. Replaced INT ( n / d) with (n \ d) 
EasterDate = 22.28125  Original Code – Alternate Calculation Method 
ReTest to Confirm Timing  
EasterDay = 30.9375  Original Code uses INT( n / d ) to convert Division Results 
EasterSunday = 20.921875  1. Replaced INT ( n / d) with (n \ d) 
EasterDate = 22.25  Original Code – Alternate Calculation Method 
ReTest to Confirm Timing  
EasterDay = 30.90625  Original Code uses INT( n / d ) to convert Division Results 
EasterSunday = 21.265625  1. Replaced INT ( n / d) with (n \ d) 
EasterDate = 22.25  Original Code – Alternate Calculation Method 
ReTest to Confirm Timing  
EasterDay = 31.078125  Original Code uses INT( n / d ) to convert Division Results 
EasterSunday = 9.171875  2. Variables DECLARED! 
EasterDate = 22.1875  Original Code – Alternate Calculation Method 
ReTest to Confirm Timing  
EasterDay = 31.109375  Original Code uses INT( n / d ) to convert Division Results 
EasterSunday = 9.171875  2. Variables DECLARED! 
EasterDate = 22.171875  Original Code – Alternate Calculation Method 
The EasterSunday procedure contains the changes described above. We achieved a total savings of approximately 22 seconds. The integer division methods used both yield the same result, however, one is clearly faster than the other.
The gains made by declaring variables were just as significant. In VBA, undeclared variables default to a “variant” type. Although variant types are more flexible by definition, performance diminishes significantly. We saved at least an additional 11 seconds simply by declaring variables. Variable declarations are to VBA as policies are to your company, they define the “size and scope” of the working environment. Undefined policies or vague specifications create ambiguity and generate waste.
Lessons Learned:
In manufacturing, a 70% improvement is significant; worthy of awards, accolades, and public recognition. The lessons learned from this example are eightfold:

For manufacturing, do not assume the current working process is the “best practice”. There is always room for improvement. Make time to understand and learn from your existing processes. Look for solutions outside of your current business or industry.

Benchmarking a current practice against another existing practice is just the incentive required to make changes. Why is one method better than another? What can we do to improve?

Policy statements can influence the work environment and execution of procedures or methods. Ambiguity and lack of clarity create waste by expending resources that are not required.

Improvements to an existing process are possible with results that out perform the nearest known competitor. We anticipated at least being able to have the two routines run at the similar speeds. We did not anticipate the final EasterSunday routine to run more than 50% faster than our simulated competitive benchmark (EasterDate).

The greatest opportunities are found where you least expect them. Learning to see problems is one of the greatest challenges that most companies face. The example presented in this simple analogy completely shatters the expression, “If it ain’t broke, don’t fix it.”

Current practices are not necessarily best practices and best practices can always be improved. Focusing on the weaknesses of your current systems or processes can result in a significant competitive edge.

Accelerated modeling can highlight opportunities for improvement that would otherwise not be revealed until full high volume production occurs. Many companies are already using process simulation software to emulate accelerated production to identify opportunities for improvement.

The most important lesson of all is this:
Speed of Execution is Important >> Thoughtful Speed of Execution is CRITICAL.
We wish you all the best of this holiday season!
Until Next Time – STAY Lean!
At the onset of the Holiday project, the task seemed relatively simple until we discovered that the rules for Easter Sunday did not follow the simple rules that applied to other holidays throughout the year. As a result we learned more about history, astronomy, and the tracking of time than we ever would have thought possible.
We also learned that Excel’s spreadsheet MOD formula is subject to precision errors and the VBA version of MOD can yield a different result than the spreadsheet version.
We also rediscovered Excel’s Leap Year bug (29Feb1900). 1900 was not a leap year. The leap year bug resides in the spreadsheet version of the date functions. The VBA date function recognizes that 29Feb1900 is not a valid date.
One thought on “22 Seconds to Burn – Excel VBA Teaches Lean Execution”