Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Dealing with Long Formulas.
Anyone who has been using Excel for any length of time knows that some formulas can get quite long. Excel handles them—as long as they are constructed correctly—but they can be a bear for humans to understand. Even after you develop your own formulas, you may have trouble understanding them weeks or months later.
One way to make formulas a bit easier to understand is to use Alt+Enter in the middle of the formula to "format" how it appears on the screen. Consider, for instance, the following long formula:
=+IF($A2=0,0,IF($B2<4264,0,IF(AND($B2>=4264,$B2<=4895), (-22.31*$C2/365),IF(AND($B2>=4895,$B2<=32760),($B2*0.093- 476.89)*$C2/365,IF($B2>32760,($B2*0.128-1623.49)*$C2/365)))))
This formula could also be written in the following manner, with Alt+Enter being pressed at the end of each line in the formula:
=+IF($A1=0,0, IF($B1<4264,0, IF(AND($B1>=4264,$B1<=4895),(-22.31*$C1/365), IF(AND($B1>=4895,$B1<=32760),($B1*0.093-476.89)*$C1/365, IF($B1>32760,($B1*0.128-1623.49)*$C1/365)))))
Now, the broken-up formula appears on five lines, even though it all appears in a single cell. The broken-up formula works just as if it were all on one line.
In addition, if you copy the complete broken-up formula from the Formula bar and paste it into a worksheet, each line in the formula is pasted into a different cell, making it easy to test each part. This is much quicker than copying and pasting parts of the original formula.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11251) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Dealing with Long Formulas.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
There are times when it can be beneficial to combine both numbers and text in the same cell. This can be easily done ...
Discover MoreWhen you need to determine an average based on a very small selection of cells from a large dataset, based on multiple ...
Discover MoreGiven a range of cells, you may at some time want to calculate the sum of only the largest values in that range. Here is ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-09-28 15:00:18
J. Woolley
@Philip
Thanks. I installed the Excel Labs add-in. It should be useful.
2024-09-28 07:49:10
Andy
The LET function (Office 365/Excel 2021) is also useful for making long formulas easier to read, combined with the tip above of using alt+enter to separate it over several lines.
2024-09-27 03:55:16
Philip
There is a free "Excel Labs" add-in available from Microsoft that includes (among other great functionalities) the previously called "Advanced Formula Environment. After adding it, it puts a button on the far right of the Home ribbon, which will give you a great editing / debugging environment for long formulas, Defined Names, ...
2024-09-25 07:55:03
Mark E Watson
For a number of years I've been using this. I do as balthamossa2b suggests break some formulas into parts. However, some are manageable with this tip. I also indent the equations (with spaces) for more help.
Another tip to make equations more readable is to use named ranges.
I created a workbook that validated the user's inputs and, if necessary, returned error messages. Those results were displayed to the user by the .NET application that uses the workbook in the background. Here's an example:
=IF(LEN_IsNull,
"Error: Length is a required value. " & B2,
IF(A_COMMENT,"No Error: Len is not empty. " & B2,"")
)
And finally, I included the if statement that checks the named range "A_COMMENT". It's usually set FALSE which results in the cell being empty. When diagnosing very complicated nested if statements I set it TRUE so the workbook shows the comments providing a text description of the results of "Passed" tests. It's pretty obvious in this example but in more complicated cases it can be very helpful.
2021-07-06 10:09:02
genius
There must be an example with the long formula
2015-04-01 11:20:53
You can also paint part of a formula, as an if, and pres F9, excel return de value of this part of de formula in the formula bar. Then press scape, and excel returns the formula, if you don´t, you get the result en the formula.
2015-04-01 10:49:13
Gary Lundblad
That is great Chuck!
Thank you!
Gary
2015-03-31 12:33:07
Dave O
This is a great tip! Simple but great. I can see that it will save time on long formulas...starting today.
2015-03-31 11:45:56
Chuck Trese
Gary,
These two (numeric) formulas give identical results:
=SUM(B12:B15)
=SUM(B12:B15) +N("explanation text here")
Also, these two (text) formulas give identical results:
=B3&B4&B5&B6
=B3&B4&B5&B6 &T(N("explanation text here"))
2015-03-31 11:38:26
Chuck Trese
+N("explanation text") works for formulas that return numbers.
For formulas that return text, you can use &T(N("explanation text"))
2015-03-31 11:10:30
Gary Lundblad
John, are you saying that you can add explanatory text in a formula without screwing up the formula? If so, can you include an example of a formula with added explanatory text?
Thank you!
Gary
2015-03-31 10:10:11
bmultack
I have been using this method for long text entries. I have my own emailer and each paragraph of the body is in one cell. Using the Alt+Enter starts the text on a new line within the cell. Just increase the line height to accommodate the entire entry. It does not start a new line in the email, just how it looks on my screen.
2015-03-31 09:05:38
Jen T
Love this tip! I've never thought to force a line feed in a formula. Great addition by John H, too. I'm using these today.
2015-03-31 08:16:45
John H has shown a great way to to Label a long formula and it an valuable addition to the current tip. Thanks.
2015-03-31 07:30:06
John H
You can also use N("bla bla bla") eg +N("this calcs this bit") which has no effect on the formula except to add some help text
2015-03-31 07:20:59
CStripling
Now this is a great tip. I have been looking for a way to make long formulas more readable and easier to troubleshoot.
2015-03-31 07:12:50
My approach to long formulas is to not use them. It's better for readability and troubleshooting to separate a long formula in shorter ones, each in one cell.
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