# Speed up your Excel Formulas [Speedy Spreadsheet Week]

* Excel formulas acting slow?* As part of our Speedy Spreadsheet Week, today lets talk about optimizing & speeding up Excel formulas. Use these tips & ideas to super-charge your sluggish workbook. Use the best practices & formula guidelines described in this post to optimize your complex worksheet models & make them faster.

## 10 Tips to Optimize & Speed up Excel Formulas

### 1. Use tables to hold the data

Starting Excel 2007 you can keep all the related data in a table. For example call center data in our recent dashboard is kept in a table. Tables can be used in formulas with structural references, can be used as a source for pivot tables etc. And since tables grow & shrink as you add / remove data, none of your formulas need to be dynamic. As an example, if you have table called ** cs**, then the formula sum(cs[column_name]) refers to sum of all values in the column_name of table cs. Even if you add more data to CS, the formula still works.

Note: You can use Excel lists in 2003 version, which are similar to tables.

**Resources to learn about Excel Tables:**

- Introduction to Excel Tables – what are they and how to use them?
- Example: Customer Service Dashboard – Data & Calculations

### 2. Use named ranges, named formulas

By using names and named formulas, you can simplify your spreadsheet. Not only that, since named ranges & named formulas can hold arrays (ie lists of values), you can hold intermediate results or values that you need to refer many times in these named formulas. This will reduce the formula overhead and makes your workbooks faster.

**Resources to learn about named ranges & named formulas**:

**Excel Formula Crash Course**: In this program, we introduce named ranges & named formulas very early on and use them in various ways thru out the course.- Musings on Live Calendar [Excel Hero]
- Examples of Named Formulas – 2012 Calendar in Excel

### 3. Use Pivot Tables

Many times, even when we do not need formulas we use them, because we can. Pivot tables are an excellent way to calculate a lot of summary values with few clicks. Once the pivot is built, you can refer to the pivot values with GETPIVOTDATA or simple cell references. This will reduce a lot of unnecessary calculations. If you are changing the data, you can just go to DATA ribbon and refresh all pivots in one go. This process works smoothly when you use **tables to hold the data.**

One of the reasons for slow workbooks is ** lot of data. **Since, pivot tables are designed to work with lots of data, by using them, you can speed up your workbooks.

**Resources to learn Pivot Tables:**

### 4. Sort your data

One of the reasons for sluggish performance is that you are searching for something in a lot of un-sorted data. You are making Excel look for a needle in a hay-stack. Many times we inherit un-sorted data thru data imports. By sorting the data & using correct operators in lookup formulas, we can instantly speedup a sluggish workbook. If you feel that sorting the data is a pain, you can even automate it so that as soon as data is refreshed, you can initiate sort procedure (thru a simple VBA macro).

**Examples on Sorting:**

- Remove duplicates & sort a list using Pivot Tables
- Sorting numbers etc. using formulas – KPI Dashboard example
- Sort text values using Formulas

### 5. Use Manual Calculation Mode

Speed is the hefty price you pay for complexity. But many times, we want our Excel workbooks to be complex, because only then they would reflect real world. In such cases, you can set formula calculations to manual mode.

Just press F9 whenever you want to run the formulas. Please note that Excel runs formulas whenever you save the file too.

### 6. Use Non-volatile formulas

There are a class of formulas in excel called as * volatile formulas.* These formulas are re-calculated whenever there is a change in the workbook. Examples of volatile formulas are RAND, NOW, TODAY, OFFSET etc. So when your worksheet has a lot of volatile formulas, any time you make a change all these formulas must be re-calculated. Thus, your worksheet becomes slow.

Solution? Simple, do not use volatile formulas. For example, instead of using OFFSET to construct a dynamic range, you can use INDEX. Since INDEX is non-volatile, it tends to be faster. Or better still, use a table.

**Resources to learn more:**

- The imposing INDEX [Excel Hero]

### 7. Keep formulas in a separate sheet

Formulas are the driving force behind any Excel workbook or model. By keeping all them in a separate worksheet(s), you minimize the chance of mistakes, omissions or repetitions. Debugging or investigating slow performance becomes an easy task when all formulas are in same place. I usually keep all the formulas in one sheet whenever I am designing a dashboard or complex workbook. This structure also helps me in thinking thru various calculations and planning the formulas in a structured way.

### 8. Write better formulas

Here are some guidelines that I follow when writing formulas.

- Built-in formulas tend to better than your own version – for example SUMIFS is easier to write and just as fast as SUMPRODUCT.
- Do not refer to entire column when you need just a few values. Do not write SUM(A:A), when you know values are only in A1:A10.
- IFERROR instead of lengthy IF(ISERROR formulas. Use IFERROR to simplify your error checking.
- Remove or Fix formula errors [how to, findout why formulas are not working]
- Remove or Reduce array formulas
- Remove or Reduce references to other workbooks.
- Remove any named ranges that result in error or missing links.
- Try to come up with alternative formulas: this not only sharpens your mind, but lets you discover better solutions.
- Do not calculate something if you do not need it.
- Do not calculate same thing twice. Use the first result second time too.

**Resources to write better formulas**:

- Introduction to SUMIFS formula
- Introduction to SUMPRODUCT formula
- Introduction to IFERROR formula
- Using Lookup formulas – VLOOKUP Week
- Examples of Array Formulas
- Excel Formula Forensics
- Excel Formula Crash Course

### 9. Desperate times need desperate measures

Sometimes, no matter what you do, the workbook remains slow. Here are a few whacky ideas that I try in such cases:

**Replace formulas with values.**I take a backup of the formulas. Then I select everything, CTRL+C, ALT+ESV. Done!**Develop the workbook from scratch:**Sometimes it helps to design the workbook afresh.**Replace external data links with actual data:**And import data by copy-pasting if needed.**Reduce the functionality:**See if the end user can live with fewer features in the workbook.**Find an alternative solution:**Trying to do everything in Excel is foolish. See if there is any external tool that can do this better & faster.

### 10. Learn new formulas & play with them

Optimization is not a one-shot exercise. It is an ongoing-business. So you need to constantly learn new formulas, new uses & play with them. This way, you see new ways to improve a sluggish workbook. To begin with, explore our Formula homework & formula forensics pages and see how you solve these problems.

## How do you speed-up your Excel formulas?

So how do you optimize & speed-up your Excel formulas? What techniques do you use? **Please share using comments.**

### Leave a Reply

This week, Speed up your Spreadsheets – Your Action Required |
Speeding up & Optimizing Excel – Tips for Charting & Formatting [Speedy Spreadsheet Week] |

## 20 Responses to “Speed up your Excel Formulas [Speedy Spreadsheet Week]”

On # 2: I don't think Excel caches arrays in named formulas.

If you have a name test referring to a function returning an array and you use =INDEX(TEST,A1), each call to test recalculates the rangename test.

I have this demo UDF:

Function DemoFunction(r As Range)

Dim vValue As Variant

Dim lRow As Long

Dim lCol As Long

vValue = r.Value

For lCol = LBound(vValue, 2) To UBound(vValue, 2)

For lRow = LBound(vValue, 1) To UBound(vValue, 1)

vValue(lRow, lCol) = 2 * vValue(lRow, lCol)

Next

Next

DemoFunction = vValue

Debug.Print r.Address

End Function

and this named range test:

Name: test

Refersto: =DemoFunction(Sheet1!$A$1:$A$7)

In cells B1 to B7, I have:

=INDEX(test,row())

This causes 7 calls to the UDF on each recalc.

However, if I control+shift+enter =test into B1:B7, one call to test is made.

Thank you so much for this Jan. I did not know about this. I know that array entered INDEX is faster than several individual INDEX formulas. I usually prefer named formulas as they are convinient and the worksheet looks clean.

For #5. Use Manual Calculation Mode, at the end you said "Please note that Excel runs formulas whenever you save the file too."

There is a way to turn this off. Click the Office Button, then Excel Options, then Formulas, then under Calculation options verify that Manual is selected and uncheck "Recalculate workbook before saving" and click OK.

hi chandoo.

hi everybody.

thank you for your awesome website.

just a speedy way to Replace formulas with values; if you have just a cell you can do this :

1-F2

2-F9

3-Enter

that's all!

i hope that this tip would help.

Regards

"Many times, even when we do not need formulas we use them, because we can" ....well said! The "imposing index" article you mention is a must read, it truly will revolutionise the way you use excel. Alot of my workbooks are distributed to people who have an old version of excel and do not need to see the workings - because of this I have written a very simple piece of code that loops through all of the calculation worksheets, and pastes as values - which resolves any compatibility issues (using formulas that arent supported in 03, and has a dramatic improvement in reopening time).

Great article on INDEX in Excel Hero (never seen so many responses in any forum as that one!)

If a file is becoming tool big and has several different table structures and you can logically split it then do so. In many cases the data being 'passed' from one section to another may only be a handfull of cells. Rather than have direct links to other workbooks I place an 'export block' in a precedent workbook then copy/pastevalue to an 'import block' in the dependent workbook. This method also avoids the problem of changed names in precedent workbooks.

@K Mac

That article is required reading for participants in the Excel Hero Academy, hence the large no of posts.

Fantastic post,

I am sure I will refer to this many times in the future.

Thank you

An approximate lookup is way faster than an exact lookup, for either vlookup or index. It can be worthwhile to look approximately once as an if condition, checking against the lookup value to see if found an exact match, then if it turns out find an exact match do the approximate lookup again to grab the needed column.

=if(vlookup(lookupvalue,array,1)=lookupvalue,vlookupvalue(array,datacolumn#,"No match")

array need to be sorted.

If there's a relatively fast rough check that can limit the cells that need a more expensive calculation, much time can be saved. examples:

-- If you don't need the calculation on, for example, inactive records, wrap the calculation in an if function that checks status.

-- Use a countif to see if you'll get a match at all in a lookup table, and only do the big, complicated multi-criteria array-formula index lookup for the records that have at least a basic match.

If there's no way to make it fast, make use of the manual calculation:

-- Set calculation to manual as mentioned above.

-- Fill the array column with placeholder text like xxxx. If you put a formula in a cell of an empty table column, it will automatically fill and calculate even if you have manual calculation set.

-- Put the formula in the first data row, and make sure it's working before copying it to the rest of the cells in the column.

-- I you have more than one column that need time-consuming formulae, set those up the same way.

-- Click on Save (with calculate on Save set) at the end of the workday.

-- Lock the computer and walk away.

-- It doesn't matter if it takes even all night, as long it's done in the morning.

-- Copy the columns and paste values to break the formulae, then save again.

Hi Chandoo,

Very well written article, covers most of the points which makes Spreadsheet/excel slow. above all this, there are 2 very basic pointers which can also be added to the above list.

1) When excel calculates, it calculates in a linear profile, i.e. top to bottom and left to right. Hence, if the spreadsheet is structured in this pattern, then there are less chances to slow up the excel.

2) Avoiding off sheet cell references and same sheet reference. excel take time to calculate, when there are offsheet references (majorly used in sumif, sumproduct, index, match).

With same sheet references, i mean, for instance sheet name is 'Sheet 1' and the formula in the A1 of the 'sheet 1' is "SUM(Sheet1!B1:D1)".

Let me know, if this makes sense.

[...] had some posts on speeding up Excel worksheets, one of the posts focuses on formulas and another he let the general readers make their suggestions. I made the suggestion that people [...]

I have seen in some cases that even incorrect formatting messes up the functionality of a formula in a cell. Avoid unnecessary formatting whereever applicable which will also reduce your workbook size.

[...] [...]

Hi Chandoo, all: do you have any tips on how to speed up pivot tables using calculated items ?

I am working on a P&L constructed in a form of pivot table with a # of calculated items. When dragging the fields around in the pivot – usually 2 — it takes about 3-5 min to complete refreshing (because it calculates everything in the pivot, not just the fields I am filtered on). Adding a 3rd field can take 20 + mins. How can I speed this process up? Turning off option DEFER LAYOUT UPDATE in table options doesn’t work here….when I make the update with it off it still takes the same, large amount of time. The source data has about 15,000 rows only, and if I remove the calculated items the speed problem goes away, so I am quite certain that is the root cause of the issue…..any ideas on this one?

Thanks in advance!

Hi Chandoo

In your very 1st tip you state that "And since tables grow & shrink as you add / remove data, none of your formulas need to be dynamic." I agree that they grow as you add more data, but much to my great annoyance, I have not found them to shrink when data is deleted/cleared!

Is there some trick to making the table automatically reduce in size to match the data??

Hi Chandoo!

Thank you for this article! I've translated it on Russian, if you don't mind. Translation may be found here:

http://www.excelworld.ru/forum/5-17254-1

Regarding #7. Keep formulas in a separate sheet

This sounds interesting, but:

- What does it mean? Most of my formulas are repeated for each data row. I sometimes drop into VBA to simplify these long winded data lines, but I don't know the programming environment nearly as well, and often get into trouble.

- I've read elsewhere that references across worksheets hinders performance, which surprises me.

Wouldn't it be cool if you could create macros using a set of spreadsheet formulas instead of dropping into VBA? I've started to use Names to do something similar, but changing arguments is the rub.

Thanks,

Carlos

I've just analyzed the impact of some tricks on the calculation time. Quite surprising: Some things have a great effect as switching the language to English (if you got Excel in German region setting, -81% of calcultion time) or avoiding SUMIFS as lookups (-53%). On the other hand, INDEX-MATCH is only insignificantly faster than VLOOKUP and using the exact range instead of whole column is only 1% faster.

The full study is here: http://professor-excel.com/performance-excel-study/