Tag: VBA

Are you an Excel Hero?

Animation of a simple spreadsheet that multipl...
Image via Wikipedia

Background

Not too long ago, I was approached by a systems consultant to consider writing an Excel solution to create a weekly production schedule for one of his clients.  The reason for using Excel will become clearer in a moment.

The current process

Sales representatives submit a unique Excel spreadsheet / file for each customer order.  All orders are saved to a common subdirectory on the company server.  Every Monday, an administrator then opens each spreadsheet and extracts information for each individual order and manually enters the relevant data into a “master” spreadsheet.  After formatting the entries, the production schedule is then created.

In this case, the client was typically managing 200 to 250 unique orders per week and the time required to create the master spreadsheet could range anywhere from 4 to 6 hours.  Since the sales team was already acclimated to using Excel, the client was reluctant to consider an alternative order management process.

The Solution

I agreed to take a look at the application and after an hour of writing some Visual Basic for Applications (VBA) code, I produced a working model that automatically processed over 200 files and created a production schedule in less than 28 seconds!  I also provided functionality to allow access to each file directly from the master as well as a few other bells and whistles!

The client was impressed by (couldn’t believe) the results and, as with any successful effort, requested additional functionality that they also never thought was possible.

Could this be you?

Although Excel is by far one of the most popular spreadsheets on the market, it is perhaps still one of the most underutilized desktop application in business today.  Although I can only speculate, I think one of the reasons for this is the overwhelming thought of having to read an ever-growing volume of books having an ever-increasing number of pages with each new release.

I would also suggest that some of Excels functions such as pivot tables and look up capabilities are so powerful that people just assume they must be complicated when this really isn’t the case at all.  I can only suggest trying them before making a judgement.

While a number of Excel solutions exist in the form of templates ranging from very specific applications such as our free Excel templates for OEE to the more general and commonly used applications such as dashboards, there are many more applications where “canned” solutions just don’t exist.

Naturally, because many people have access to Excel, they find themselves creating their own solutions “on demand” as was the case with the production schedule above.

An even greater concern is the number of “orphan’ spreadsheets that exist outside the scope of any managed data infrastructure.  The danger here is that these solutions may unknowingly compromise the integrity of the current management system.

I contend that orphan solutions eventually become the hidden or “unknown” extension of the existing infrastructure and present a real opportunity yet to be uncovered by many organizations.

“Homegrown” Solutions

For cases where customization is required, someone in the organization is usually tasked with creating a spreadsheet solution.  Unfortunately, these same individuals are not necessarily as capable as we may first think.  I discussed this concern to some degree in Lean Office with Excel and VBA and also became a topic of discussion at Daily Dose of Excel’s Learn VBA to be Lean.

The result is often a solution that “appears” to meet the requirements – at least on paper.  I have found that these same spreadsheet solutions seldom take advantage of even the simplest functions that Excel has to offer including the most basic arithmetic functions such as SUM as suggested by the animated graphic that accompanies this post.

Although the articles referred to above focus on Visual Basic for Applications (VBA), there are many other very powerful functions that can be used to make better use of Excel’s functionality and increase it’s value in terms of providing effective and efficient solutions.

Getting the Knowledge

There are a number of ways to learn Excel ranging from formal training, reading books, and, of course, the internet.  Although I have been using spreadsheets since their inception, I still consider myself to be a student in many respects.

I recommend reading and working through at least one good general knowledge Excel book and one good introductory book on VBA such as Excel 2007 VBA Programming for Dummies or Excel 2007 Power Programming with VBA.  I have listed a number of recommended titles on our Excel Books page.

With a little knowledge in hand, I recommend visiting the sites that I have learned to trust as listed on our Websites (Excel) page.  Each of these sites present powerful solutions to many common problems.  They also offer full explanations and practical examples that you can use in your own spreadsheets.

Excel is best learned by doing.  Having an application to work on and exploring solutions that may be available to you can be a most rewarding experience.  This is especially true when they can be implemented and put to good use with immediate results.

Getting to Lean

Obviously all of this learning isn’t going to happen over night, however, you will be surprised how much can be learned in a relatively short period of time.  The time saved by creating a more efficient solution in many cases will offset much of the time spent learning.

The initial challenge is to determine what spreadsheets solutions are in existence and why.  The number may surprise you.  If your company has an IT department, I would task them with this assignment.

As demonstrated by the case study presented earlier, the hours saved can be significant.  The solution I created offers the added advantage of being able to refresh the production schedule at any time, in real-time.  In other words, it is now an everyday event, not just a “Monday” event.

Your skills will improve over time and with each application.  As you increase your learning, old solutions can be upgraded to reflect even more functionality adding even more value.  The more comfortable you become with Excel, the more useful it will be as a tool for data analysis in other areas of the company, including lean initiatives.

I continue to be surprised by the quality of solutions that some companies have created simply because they took the time to understand and learn more about Excel for themselves.  In some cases companies have hired outside support to help them in the process.

There are pros and cons for how spreadsheet solutions are developed and you should consider them as you look to develop your own solutions.  Of course you can always be the Excel Hero by taking the time to learn Excel for yourself.  The added benefit is how much more you may learn about other processes in your company.  Finally, you may just be surprised how in demand these skills are.

Speaking of hero’s, I recently added ExcelHero.com to our list of trusted sites and to Daniel Ferry’s credit, it also inspired the title of this post.

Until Next Time – STAY lean!

Vergence Analytics
Twitter:  @Versalytics
Advertisements

22 Seconds to Burn – Excel VBA Teaches Lean Execution

Cover of "Excel 2003 Power Programming wi...
Cover via Amazon

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:

  1. 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.
  2. 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
Re-Test 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
Re-Test 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
Re-Test 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
Re-Test 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 eight-fold:

  1. 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.
  2. 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?
  3. 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.
  4. 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).
  5. 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.”
  6. 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.
  7. 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.
  8. 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!

Vergence Analytics

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 (29-Feb-1900).   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 29-Feb-1900 is not a valid date.