Excel Speedup & Optimization Tips by Experts [Speedy Spreadsheet Week]

Share

Facebook
Twitter
LinkedIn

As part of Speedy Spreadsheet Week, I have emailed a few renowned Excel experts and asked them to share their tips & ideas to speedup Excel. Today, I am glad to present a collection of the tips shared by them.

Excel Speedup & Optimization Tips by Experts

Excel Speeding up & Optimization Tips by Hui

About Hui:
Hui (Ian Huitson) has been writing & contributing to Chandoo.org for more than 2 years. Many of you know him from Formula Forensics & Data table related articles on Chandoo.org. See about Hui page for more about him.

In no particular order:

  • Minimize the use of Volatile Functions
  • Organize your workbook layout and data methodically
  • Where possible use fixed values or Named formulas instead of lookups even if the values only change rarely, flag those for manual checking
  • Don’t Start equations with a + that actually adds 0.4% calculation time
  • Minimize use of the Data Table command to running summaries only at the end of a project
  • Review the logic of the model and all if’s or lookup choices for necessity or alternatives
  • Use negatives instead of multiple positives where appropriate in conjunction with If’s and Lookups
  • Learn about Conjunctive Truth Tables, they Rock for reporting
  • Array formulas can do the work of dozens of normal cells, but use cautiously
  • Use Named Formulas and UDF’s instead of multiple Helper Cells/Rows or Columns
  • Minimize of us Conditional Formatting
  • Minimize use of linked workbooks especially if over network drives
  • Take an advanced Excel course like the ExcelHero Academy
  • Minimize the use of Excel 2007

Links:

Excel Speeding up & Optimization Tips by George

About George:
George runs Excel Unusual, where you can learn about using Excel for engineering, simulations & games. In his work, he builds complex spreadsheet models all the time. So I asked him to share a few tactics with us. He wrote 2 articles in response to my request.

Links:

Excel Speeding up & Optimization Tips by Gregory

About George:
Gregory runs Excel Semipro, where he shares Excel tips & ideas. I asked him to contribute to the Speedy Spreadsheet Week. This is what he says,

Tips by George:

To speed up my worksheet files, I have one primary rule: do not use the OFFSET function, which is volatile and can slow things down considerably. In newer spreadsheets I use Tables and The imposing INDEX function to keep ranges automatically updated. In Excel 2003 I use an event-based approach, with named ranges, the worksheet deactivate module, and VBA to keep lists and ranges updated.

Links:

Excel Speeding up & Optimization Tips by Luke

About Luke:
Luke is one of the Excel Ninjas at Chandoo.org where he contributed more than 1000 posts. I asked Luke to share some optimization tips based on his vast experience of using Excel & helping others. This is what he suggests:

  1. In VB, whenever I see a line like Selection.something that’s usually an indicator that I’m using extra lines. Either I need to apply the method directly to the object instead of selecting it, or I need to use a With statement.
  2. With Event macros, don’t forget the all-important lines of Application.EnableEvents = False and Application.EnableEvents = True so that you don’t cause multiple events to be triggered.
  3. See a section of code that you’re repeating? Probably need to make this a separate Sub or Function that you can then reference from the main code.
  4. When building your formula page, think top-down. Cells near the top of worksheet should be referenced in formulas that are below, not vice-versa. XL likes to calculate left to right, top to bottom. Scattering cell references around makes it work harder.
  5. When using large amounts of data that you want to be charted, sometimes I’ll build a formula sheet within the workbook with data, and then just build another workbook that uses a data query (referencing the formula results) to generate the charts.
  6. This might be more along the lines of auditing a worksheet, but sometimes it’s hard to see how I’ve laid out my constants and formulas, and using a worksheet map helps bring things into focus (related: create a worksheet map)

Want to become better in Excel? Join Chandoo.org courses

Excel School

Learn Excel from basics to advanced level. Create awesome reports, dashboards & workbooks.

Click here to know more

VBA Classes

Learn VBA & Macros step-by-step. Build complex workbooks, automate boring tasks and do awesome stuff.

Click here to know more

Excel Speeding up & Optimization Tips by Narayan

About Narayan:
Narayan is one of the Excel Ninjas at Chandoo.org where he contributed more than 1000 posts. I asked Narayan to share some optimization tips based on his vast experience of using Excel & helping others. This is what he suggests:

Period-to-Date and Cumulative SUMs
There are two methods of doing period-to-date or cumulative SUMs. Suppose the numbers that you want to cumulatively SUM are in column A, and you want column B to contain the cumulative sum; you can do either of the following:
You can create a formula in column B such as =SUM($A$1:$A2) and drag it down as far as you need. The beginning cell of the SUM is anchored in A1, but because the finishing cell has a relative row reference, it automatically increases for each row.
You can create a formula such as =$A1 in cell B1 and =$B1+$A2 in B2 and drag it down as far as you need. This calculates the cumulative cell by adding this row’s number to the previous cumulative SUM.
For 1,000 rows, the first method makes Excel do about 500,000 calculations, but the second method makes Excel do only about 2,000 calculations.

Subtotals

Use the SUBTOTAL function to SUM filtered lists. The SUBTOTAL function is useful because, unlike SUM, it ignores the following:
Hidden rows that result from filtering a list. Starting in Excel 2003, you can also make SUBTOTAL ignore all hidden rows, not just filtered rows.
Other SUBTOTAL functions.

Using SUMPRODUCT to Multiply and Add Ranges and Arrays.
In cases like weighted average calculations, where you need to multiply a range of numbers by another range of numbers and sum the results, using the comma syntax for SUMPRODUCT can be 20 to 25 percent faster than an array-entered SUM.
{=SUM($D$2:$D$10301*$E$2:$E$10301)}
=SUMPRODUCT($D$2:$D$10301*$E$2:$E$10301)
=SUMPRODUCT($D$2:$D$10301,$E$2:$E$10301)

These three formulas all produce the same result, but the third formula, which uses the comma syntax for SUMPRODUCT, takes only about 77 percent of the time to calculate that the other two formulas need.

Dynamic Ranges

These are most often created using the OFFSET and COUNTA functions , as in the following :
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A)-1,1)

Sometimes , when data is stored in the form of records , so that all columns have data to the same extent , there may be several dynamic ranges ; say we have ORDER_ID in column A , CUSTOMER_ID in column B , and the AMOUNT in column C. Thus there may be several dynamic ranges as follows :
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A)-1,1)
=OFFSET(Sheet1!$B$1,0,0,COUNTA(Sheet1!$B:$B)-1,1)
=OFFSET(Sheet1!$C$1,0,0,COUNTA(Sheet1!$C:$C)-1,1)

These can be simplified to :
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A)-1,1)
=OFFSET(Sheet1!$B$1,0,0,COUNTA(Sheet1!$A:$A)-1,1)
=OFFSET(Sheet1!$C$1,0,0,COUNTA(Sheet1!$A:$A)-1,1)

These can then be optimized by storing the COUNTA value in a cell , and using the cell reference within the OFFSET formula :
=OFFSET(Sheet1!$A$1,0,0,Sheet1!$F$1,1)
=OFFSET(Sheet1!$B$1,0,0, Sheet1!$F$1,1)
=OFFSET(Sheet1!$C$1,0,0, Sheet1!$F$1,1)

Where Sheet1!$F$1 contains the formula : =COUNTA(Sheet1!$A:$A)-1
For more, refer to MSDN.

Resetting the USED RANGE

Pressing CTRL END will take the cursor and place it on the cell which Excel thinks is the last used cell in the worksheet.
Suppose you do this , and the cursor lands on D27 ; now navigate to any cell which is as far away as you can imagine , say AA3456 ; enter any character , even a space will do ; then clear the cell contents by pressing the DEL key.
Pressing CTRL END will now take the cursor to AA3456.
To reset the USED RANGE , go to the Immediate Window of the VBA Project , and enter the following statement :
Application.ActiveSheet.UsedRange
Your used range should now be reset to its earlier value of D27 ; pressing CTRL END will now take the cursor to D27.
Refer to this Stackoverflow discussion for more.

Excel Speeding up & Optimization Tips by Jordan

About Jordan:
Jordan runs Option Explicit, an Excel VBA blog. He shared these tips with us,

  • When reading and writing to ranges, use .value2 (this is noticeable for large, iterative calculations)
  • Ensure that ALL spreadsheet errors are handled. The most common errors I see ignored are #Ref errors and #Div (for dividing by zero). Use Go To Special… to find these errors and either delete them or use IFERROR to handle them. In my opinion, Excel errors are one of the biggest contributing factors to slow spreadsheets.
  • When using INDEX, include the row or column number even if you don’t need it. For example, if I’m pulling data from only one column, I need only write =INDEX(A1:A10, 1) to pull the first item. However, =INDEX(A1:A10, 1, 1) appears to be a hair faster. Try it.
  • Cut down on Lookup functions. In many instances, the lookup table has already encoded information in the correct order. Instead of looking up, say, Stage 2, just use INDEX on the desired column and pull from row 2.

Thanks to Hui, George, Gregory, Luke, Narayan & Jordan

Many thanks to all of you for sharing these ideas & tips so that we can speed up Excel. If you found these tips useful, say thanks to the contributors.

More on Excel Optimization & Speeding up:

Read these articles too,

Want to become better in Excel? Join Chandoo.org courses

Excel School

Learn Excel from basics to advanced level. Create awesome reports, dashboards & workbooks.

Click here to know more

VBA Classes

Learn VBA & Macros step-by-step. Build complex workbooks, automate boring tasks and do awesome stuff.

Click here to know more

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

41 Responses to “Calculate Elapsed Time in Excel [Quick Tips]”

  1. Oliver Montero says:

    Hi Chandoo,

    To calculate time lapses in excel I usually use the DATEDIF function. Even though is undocumented by MS there is a great explanation of its use in Chip Pearson's site :

    http://www.cpearson.com/excel/datedif.aspx

    Is pretty easy to use and has great flexibility.

    See you and keep Excelling!!!

  2. Glen Feechan says:

    Another great article, I will be linking to it on my blog.

  3. L. Quezada says:

    Oliver:

    Yes, I think that DATEDIFF do it better.

  4. Andy says:

    Great post! This a fantastic tutorial on calculating elapsed time in Excel that could be helpful even to a novice user. Keep up the useful tips!

    Also, the Office community on Facebook could really benefit from you knowledge! Check it out at http://www.facebook.com/office

    Cheers,
    Andy
    MSFT Office Outreach Team

  5. Modeste says:

    hi, Chandoo !!!
    for elapsed time , we can use this unique formula either for hours, minutes or seconds : NOW()-A1)
    but using respective special number formats
    for hours : [h] ==> 46553
    for minutes : [m] ==>2793212
    for seconds : [s] ==> 167592763

    We can also use mean duration for years (orbital period of the Earth around the Sun : i-e tropical year) which is : 365.25 days
    and mean duration for month : 365.25/12 days

    be Excelent !!!!

  6. Chandoo says:

    @Oliver... Thanks for the pointer to datediff(). I will update the post with information about this as well.

    @Glen... thanks for the linklove 🙂

    @Andy... Welcome. Thanks for telling us about the office community on FB.

    @Modeste ... that is very cool. I will remember these formatting codes for an upcoming article on number formatting codes 🙂

  7. Tony says:

    Great tip Chandoo! I use the formula to calculate years elapsed all the time. It can seriously help save a ton of time with calculations. Also, NETWORKDAYS is one that helps and can seriously impress a boss. Keep up the great work here!

  8. Andy says:

    No problem! I will definitely be directing people with tough Excel questions to your blog. Keep up the great posts!

    Andy
    MSFT Office Outreach Team

  9. PaulS says:

    Hi,
    always great posts and a good way to start my day

    but regarding the elapsed time calculations: have you never noticed that there is a result difference between using =TODAY()-A1 and using =NETWORKDAYS(A1,TODAY())?
    try it for A1= a Monday such as 21sep09 and "today" is e.g. a Thursday; you get 3 or 4 respectively as a result, depending on the formula used; this is because formula =networkdays() always includes both the startdate and the end date and not only the time between these 2.
    This is easily corrected/compensated bij always adding a -1 to the =networkdays() formula because the majority of us will count startday as day 0 and then the result will be consistent across the different formulas.

    However, you then get into trouble if you calculate the networkdays for a date further in the past and where either the start or end date falls in a weekend.

    just thought to point this out as to me these formula's are not interchangeable just like that!

    have a great day!
    Paul

  10. Captn_zee says:

    =DATEDIF([DOJ],TODAY(),"Y") & " Y, " & DATEDIF([DOJ],TODAY(),"YM") & " M, " & DATEDIF([DOJ],TODAY(),"MD") & " D"

    This will fix your 30 Days problem

  11. Amol says:

    I calculated the time diff between two date+ times by subtracting 2 cells & custom formatted it to "d hh:mm" format.

    E.g.
    Cell A1 04-Jan-12 6:00 PM
    Cell A2 05-Jan-12 4:45 PM

    Cell A3 0 22:45 (formula: =A1-A2)

    Wat shud i do 2 not display the "zero" values i.e. no. of days in this case is zero hence the cell shud display " 22: 45" and not "0: 22: 45".

  12. Ana says:

    Hi Chandoo,

    If possible to compute the interval of time and date in one column.
    In column C I would like to compute the total days and hours . What formula ? Please help
    Example.
    Column A Column B
    2/13/12 3:30 AM 2/14/12 12:00 AM

  13. Prasad DN says:

    In referenc to Elapsed time in months

    To calculate the elapsed time in months, we can use the formula =(NOW()-A1)/30. This returns the value in 30 day months.

    I use to apply formula =ROUND((TODAY()-A1)/30,0). Today, I faced a peculiar situation, A1 has date 01-Mar-2009, and today being 01-Mar-2012, it should be 36 months, but it is showing 37 months!!

    Any suggestions to avoid such errors?

    Regards,
    Prasad DN

  14. pete says:

    All I want to do is add up a series of times and receive a reply that gives me a total. What I used to do was subtrace the end time from the start time and format the result as [hh]:mm but this doesn't seem to work anymore. How has Bill Gates confounded me?

    • Hui says:

      @Pete
      I use Excel 2010 and it still works

      The times must be entered as times in the format hh:mm:ss or hh:mm without seconds
      Adding up times is as simple as =Sum(Range) or =Sum(A2:A10)
      then using a Custom Number format as you have mentioned [h]:mm

      If this isn't working, 2 ideas
      1. Check your times are times and not text
      2. Can you share your data or file with us?

  15. Kent in Wichita says:

    My hospital tracks times from patient arrival to various procedures or treatments. When those times cross over midnight, the regular formulas (2nd time minus first time) don’t work because the result is negative and Excel (2007) won’t show a negative number in time format.
    I couldn’t find a solution here (chandoo.org) but found one elsewhere that worked and it’s very simple. I would like to share it.
    Assuming 1st time in A1 (column for patient arrival time) (11:00 PM), and 2nd time in B1 (column for x-ray given) (12:30 AM)). Should be 1:30 elapsed time.
    =B1-A1+(B1<A1) [This comparison is the key to the solution.]
    =12:30 AM – 11:00 PM + (12:30 AM < 11:00 PM)
    =0.0208 – 0.9583 + (True)
    =-0.9375 + (1) [This is the key! If it is false, Excel adds 0. If it’s true, Excel adds 1 and that is what corrects the negative number. Now Excel can interpret the number as a time.]
    =0.0625
    Converted to hh:mm = 1:30
    I wrapped this formula inside an IFERROR one to alert my data entry person if she messed up and applied it to lots of different columns and it has worked wonderfully. No more complaints from the data entry person who just plugs in times from medical charts.
     

  16. shashidhar says:

    HI,
     
    I am working on a Xl application..
    I want to capture time between two clicks.
    Ex, in my application during run somewhere I press OK button and then I click Cancel.. I want to measure time between these two clicks... Is it possible??
    Pls help on this...

    • Hui says:

      @shashidhar
      The answer is Yes
      You will have to add an appropriate VBA event to start and stop a timer.
      There are techniques which can time to the millisecond so maybe look those up on the net


  17. William W. says:

    WOW!!!!!! I truly love your excel time format program! WHOOOO! I am very interested in how the time formats "update" (manually on a physical keyboard) that "updates" the time into its respective decimal time formats, such as:
    YYYY.yyyy, HH.hhh, etc...

    How do those formulas or equations work if not in Excel mode? Example: TI calculators, Word, or any other computer language programming? Just wanted to see how it works. E-mail me at Ultra64848689Ti@gmail.com.

    Thanks again for an EXCELLENT Excel program into decimal time formats!
    Here's an idea: how about creating an APP for iOS and Android? Just wanted to point that out. =-D

  18. Phil K says:

    Regarding the elapsed time in months:
    I made this function to determine the time elapsed since a date using the number of days in each respective month. It's a simple subtraction and I think it works very well:((Year Today-Year A1)*12++(Month Today - Month A1)+(Day Today/Days in Month Today)-Days A1/Days in month A1)

    Here's the function:
    =((YEAR(TODAY())-YEAR(A1))*12)+(MONTH(TODAY())-MONTH(A1))+(DAY(TODAY())/DAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,0))-DAY(A1)/DAY(DATE(YEAR(A1),MONTH(A1)+1,0)))

    Have a Merry Christmas everyone!!

  19. Christian says:

    I need the ability to calculate how much progress we have made between two dates and I want to represent that as a percentage.

    I am thinking this would be a combination of today, networkdays & dividing the days elapsed vs the total days. Then it should be as easy as formatting my cell. Any help would be greatly appreciated.

    • Hui... says:

      @Christian
      Your correct
      dates are just numbers and so you can use simple math to derive the percentage
      =(Date Now-Start Date)/(End date-Start date)
      that will give you a number between 0 and 1
      which you can format as a %'age

  20. venkatesh says:

    is there a way out to calculate the productivity for an employee

    The day start is at 08:00 and day end is 20:00

    The start date / time is recorded and end date / time is recorded

    I want to calculate the timelapse taking into consideration the day begin and dayend time.

    If the work begins and ends the same day, a simple formula b1-a1 would compute the productivity.

    But if the process remains incomplete and is carried over to the next day, then timelines to be computed accordingly

    to clarify,
    if start time of an activity is 03/15/2015 18:00 hrs and end time is 03/16/2015 11:00 hrs, then the resultant formula should be 5 hrs (ie 18:00 to 20:00 hrs on day1 + 08:00 to 11:00 hrs on day2) ie 2+3

    please guide.

    • Kent in Wichita says:

      Venkatesh, try (b1-a1)-0.5

      This will subtract the fixed amount of time between shifts, 12 hours. If the time between shifts varies, then you could reference other cells that contain the variables.

  21. aria says:

    Please help. when I use the networking days formula I get a date (2-may-00) I want actual number of days. I managing projects and I need to know how many days have passed since we received a project to the current date. Please help Thanks

  22. Dan S says:

    You rock! I looked at 17 other sites and they all did not work. Yours did. Thanks!

  23. modeste says:

    Hi folks ...
    calculating age in years , months and days
    =text(now()-a1,"yy")&" y " &text(now()-a1,"mm")-1 &" m "&text(now()-a1,"dd") & " d"

  24. Dan S says:

    Hi, the Elapsed time in days [ =TODAY()-A1 ] works great however, if I do not have a date in A1, it shows 42157. Anyway to get it to display 0 or a Null value?

  25. Veena says:

    Hi Chandoo,

    This might be a challenge - I am looking to calculate elapsed time between two columns

    Start date Complete date
    9/9/2015 7:21 10/2/2015 11:01

    I need to take into account the following:
    1) The employee works 7:00-3:15 pm each day
    2) Std Work hours are 7hrs 45 min each day
    3) Need to take into account all holidays in between start and end date
    4) Work week is Mon through Friday.

    Can you help?

    Thanks!

  26. zaidan says:

    Hi, i have a certain name (wilium) in column A and against this name i have 2 option, 1 Done and 2 Inprogress. i want that i count done again wilium and count inprogress against wilium separately. which formula will work for it??

  27. zaidan says:

    Hi, i have a certain name (wilium) in column A and against this name i have 2 option, 1 Done and 2 Inprogress in column C. i want that i count done again wilium and count inprogress against wilium separately. which formula will work for it??

  28. Augustine Boltz says:

    Year, month, day results for DoB.
    The formulas I have found on the net and the datedif function do not work. This is what I came up with using a Microsoft support paper dated April 1997 with some modifications:
    IF(OR(A2>$A$1,ISBLANK(A2)),"",IF(YEAR($A$1)=YEAR(A2),0,IF(MONTH($A$1)>=MONTH(A2),YEAR($A$1)-YEAR(A2),YEAR($A$1)-YEAR(A2)-1))&" years "&MONTH($A$1)-MONTH(A2)+IF(AND(MONTH($A$1)<=MONTH(A2),DAY($A$1)<DAY(A2)),11,IF(AND(MONTH($A$1)=DAY(A2)),12,IF(AND(MONTH($A$1)>MONTH(A2),DAY($A$1)=DAY(A2),ABS(DAY($A$1)-DAY(A2)),DAY(EOMONTH(A2,0))-DAY(A2)+DAY($A$1))&" days")
    Check it out...

    • modeste says:

      Hi, Augustin

      what about :
      calculating age in years , months and days
      =YEAR(NOW()-DoB)-1900 & " y " & MONTH(NOW()-DoB)-1 & " m " & DAY(NOW()-DoB) & " d"

  29. Jenna says:

    Hi Chandoo,

    I am looking for help with the elapse time formula. I have a recruitment tracking sheet where we track the number of days the positions are opened, and when they are finally closed.

    The opened positions will have a running turnaround time (TAT) formula and I am using this formula:
    =NETWORKDAYS (start_date, TODAY (), Holidays2018)

    Now, without disrupting the running TAT formula, how do I then get the TAT to stop when we have a final end date? All the information below is row:
    - start_date --> Cell A
    - TODAY () --> cell B
    - end_date --> Cell C

    Hope you are able to help. Thanks!

  30. Athena says:

    Thank you for this helpful article. I was trying for days now to figure it out. Now the only issue I have is that if I do not have a value inputed for =TODAY()-[@[Date Precured]] Date Precured then it shows 44055. How can I get it to leave it blank if there is no data? Thanks again!!!

Leave a Reply