Wednesday, October 4, 2017

How to avoid broken formulas

How to avoid broken formulas

If Excel can't resolve a formula you're trying to create, you may get an error message like this one:

Image of Excel's "Problem with this formula" dialog

Unfortunately, this means that Excel can't understand what you're trying to do, so you might just want to get out of here and start over.

Start by clicking OK or press ESC to close the error message.

You'll return to the cell with the broken formula, which will be in edit mode, and Excel will highlight the spot where it's having a problem. If you still don't know what to do from there and want to start over, you can press ESC again, or click the Cancel button in the formula bar, which will exit you out of edit mode.

Image of the Formula Bar Cancel button

If you're not sure what to do at this point or what kind of help you need, you can search for similar questions in the Excel Community Forum, or post one of your own.

Link to the Excel Community Forum

If you want to move forward, then the following checklist provides troubleshooting steps to help you figure out what may have gone wrong in your formulas.

Excel throws a variety of hash (#) errors such as #VALUE!, #REF!, #NUM, #N/A, #DIV/0!, #NAME?, and #NULL!, to indicate something in your formula is not working right. For example, the #VALUE! error is caused by incorrect formatting, or unsupported data types in arguments. Or, you will see the #REF! error if a formula refers to cells that have been deleted or replaced with other data. Troubleshooting guidance will differ for each error.

Note: #### is not a formula-related error. It just means that the column isn't wide enough to display the cell contents. Simply drag the column to widen it, or go to Home > Format > AutoFit Column Width.

Image of Home > Format > AutoFit Column Width

Refer to any of the following topics corresponding to the hash error that you see:

Each time you open a spreadsheet that contains formulas referring to values in other spreadsheets, you will be prompted to update the references or leave them as-is.

Broken references dialog box in Excel

Excel displays the above dialog box to make sure that the formulas in the current spreadsheet always point to the most updated value, in case the reference value has changed. You can choose to update the references, or skip if you don't want to update. Even if you choose to not update the references, you can always manually update the links in the spreadsheet whenever you want.

You can always disable the dialog box from appearing at start up. To do that, go to File > Options > Advanced > General, and uncheck Ask to update automatic links. In Excel 2007 you would click the Office Button > Excel Options. Office 2007 button

Image of the Ask to update automatic link option

Important: If this is the first time you are working with broken links in formulas, need a refresher on resolving broken links, or you don't know whether to update the references, see Control when external references (links) are updated.

If the formula doesn't display the value, follow these steps:

  • Make sure that the Excel is set to show formulas in your spreadsheet. To do this, click the Formulas tab, and in the Formula Auditing group, click Show Formulas.

    Tip: You can also use the keyboard shortcut Ctrl + ` (the key above the Tab key). When you do this, your columns will automatically widen to display your formulas, but don't worry, when you toggle back to normal view your columns will resize.

  • If the above step still doesn't resolve the issue, it's possible the cell is formatted as text. You can right-click on the cell and select Format Cells > General (or Ctrl + 1), then press F2 > Enter to change the format.

  • If you have a large range of cells in a column that are formatted as text, then you can select the range, apply the number format of you choice and go to Data > Text to Column > Finish. This will apply the format to all of the selected cells.

    Image of Data > Text to Columns dialog

When a formula does not calculate, you have to check if automatic calculation is enabled in Excel. Formulas will not calculate if manual calculation is enabled. Follow these steps to check for Automatic calculation:

  1. Click the File tab, click Options, and then click the Formulas category.

  2. In the Calculation options section, under Workbook Calculation, make sure the Automatic option is selected.

    Image of Automatic & Manual Calculation options

For more information on calculations, see Change formula recalculation, iteration, or precision.

A circular reference occurs when a formula refers to the cell that it is located in. The fix is to either move the formula to another cell or change the formula syntax, one that avoids circular references. However, in some scenarios you may need circular references because they cause your functions to iterate—repeat until a specific numeric condition is met. In such a case, you will need to enable Iterative Calculation.

For more information on circular references, see Find and fix a circular reference

If your entry doesn't start with an equal sign, it isn't a formula, and won't be calculated—a common mistake.

When you type something like SUM(A1:A10), Excel shows the text string SUM(A1:A10) instead of a formula result. Now if you type 11/2, Excel shows a date, such as 2-Nov or 11/02/2009, instead of dividing 11 by 2.

To avoid these unexpected results, always start the function with an equal sign. For example, type: =SUM(A1:A10) and =11/2

When you use a function in a formula, each opening parenthesis needs a closing parenthesis for the function to work correctly, so make sure that all parentheses are part of a matching pair. For example, the formula =IF(B5<0),"Not valid",B5*1.05) won't work because there are two closing parentheses but only one opening parenthesis. The correct formula would look like this: =IF(B5<0,"Not valid",B5*1.05).

Excel functions have arguments—values you need to provide for the function to work. Only a few functions (such as PI or TODAY) take no arguments. Check the formula syntax that appears as you start typing in the function, to make sure the function has the required arguments.

For example, the UPPER function accepts only one string of text or cell reference as its argument: =UPPER("hello") or =UPPER(C2)

Note: You will see the function's arguments listed in a floating function reference toolbar beneath the formula as you are typing it.

Screen shot of the Function Reference toolbar
Function reference toolbar

Also, some functions, such as SUM, require numerical arguments only, while other functions, such as REPLACE, require a text value for at least one of their arguments. If you use the wrong data type, functions might return unexpected results or show a #VALUE! error.

If you need to quickly look up the syntax of a particular function, see the list of Excel functions (by category).

Don't enter numbers formatted with dollar signs ($) or decimal separators (,) in formulas, because dollar signs indicate Absolute References and commas are argument separators. Instead of entering $1,000, enter 1000 in the formula.

If you use formatted numbers in arguments, you'll get unexpected calculation results, but you may also see the #NUM! error. For example, if you enter the formula =ABS(-2,134) to find the absolute value of -2134, Excel shows the #NUM! error, because the ABS function accepts only one argument.

Note: You can format the formula result with decimal separators and currency symbols after you enter the formula using unformatted numbers (constants). It's generally not a good idea to put constants in formulas, because they can be hard to find if you need to update later, and they are more prone to being typed incorrectly. It's much better to put your constants in cells, where they are out in the open and easily referenced.

Your formula might not return expected results if the cell's data type can't be used in calculations. For example, if you enter a simple formula =2+3 in a cell that's formatted as text, Excel can't calculate the data you entered. All you'll see in the cell is =2+3. To fix this, change the cell's data type from Text to General like this:

  1. Select the cell.

  2. Click Home > arrow next to Number Format (or press Ctrl + 1), and click General.

  3. Press F2 to put the cell in the edit mode, and then press Enter to accept the formula.

A date you enter in a cell that's using the Number data type might be shown as a numeric date value instead of a date. To show a number as a date, pick a Date format in the Number Format gallery.

It's fairly common to use x as the multiplication operator in a formula, but Excel can only accept the asterisk (*) for multiplication. If you use constants in your formula, Excel shows an error message and can fix the formula for you by replacing the x with the asterisk (*).

Message box asking to replace x with * for multiplication
Error message using x with constants to multiply instead of *

However, if you use cell references, Excel will return a #NAME? error.

#NAME? error when using x with cell references instead of * for multiplication
#NAME? error using x with cell references instead of *

If you create a formula that includes text, enclose the text in quotation marks.

For example, the formula ="Today is " & TEXT(TODAY(),"dddd, mmmm dd") combines the text "Today is " with the results of the TEXT and TODAY functions, and returns say something like Today is Monday, May 30.

In the formula, "Today is " has a space before the ending quotation mark to provide the blank space you want between the words "Today is" and "Monday, May 30." Without quotation marks around the text, the formula might show the #NAME? error.

You can combine (or nest) up to 64 levels of functions within a formula.

For example, the formula =IF(SQRT(PI())<2,"Less than two!","More than two!") has 3 levels of functions: The PI function is nested inside the SQRT function, which in turn is nested inside the IF function.

When you type a reference to values or cells in another worksheet, and the name of that sheet has a non-alphabetical character (such as a space), enclose the name in single quotation marks (').

For example, to return the value from cell D3 in a worksheet named Quarterly Data in your workbook, type: ='Quarterly Data'!D3. Without the quotation marks around the sheet name, the formula shows the #NAME? error.

You can also click the values or cells in another sheet to refer to them in your formula. Excel then automatically adds the quotation marks around the sheet names.

When you type a reference to values or cells in another workbook, include the workbook name enclosed in square brackets ([]) followed by the name of the worksheet that has the values or cells.

For example, to refer to cells A1 through A8 on the Sales sheet in the Q2 Operations workbook that's open in Excel, type: =[Q2 Operations.xlsx]Sales!A1:A8. Without the square brackets, the formula shows the #REF! error.

If the workbook isn't open in Excel, type the full path to the file.

For example, =ROWS('C:\My Documents\[Q2 Operations.xlsx]Sales'!A1:A8).

Note:  If the full path has space characters, enclose the path in single quotation marks (at the beginning of the path and after the name of the worksheet, before the exclamation point).

Tip: The easiest way to get the path to the other workbook is to open the other workbook, then from your original workbook, type =, then use Alt+Tab to shift to the other workbook and select any cell on the sheet you want. Then close the source workbook. Your formula will automatically update to display the full file path and sheet name along with the required syntax. You can even copy and paste the path and use wherever you need it.

Dividing a cell by another cell that has zero (0) or no value results in a #DIV/0! error.

To avoid this error, you can address it directly and test for the existence of the denominator.

=IF(B1,A1/B1,0)

Which says IF(B1 exists, then divide A1 by B1, otherwise return a 0).

Always check to see if you have any formulas that refer to data in cells, ranges, defined names, worksheets, or workbooks, before you delete anything. You can then replace these formulas with their results before you remove the referenced data.

If you can't replace the formulas with their results, review this information about the errors and possible solutions:

  • If a formula refers to cells that have been deleted or replaced with other data and returns a #REF! error, select the cell with the #REF! error. In the formula bar, select #REF! and delete it. Then, reenter the range for the formula.

  • If a defined name is missing, and a formula that refers to that name returns a #NAME? error, define a new name that refers to the range you want, or change the formula to refer directly to the range of cells (for example, A2:D8).

  • If a worksheet is missing, and a formula that refers to it returns a #REF! error, there's no way to fix this, unfortunately—a worksheet that's been deleted can't be recovered.

  • If a workbook is missing, a formula that refers to it remains intact until you update the formula.

    For example, if your formula is =[Book1.xlsx]Sheet1'!A1 and you no longer have Book1.xlsx, the values referenced in that workbook stay available. However, if you edit and save a formula that refers to that workbook, Excel shows the Update Values dialog box and prompts you to enter a file name. Click Cancel, and then make sure that this data isn't lost by replacing the formulas that refer to the missing workbook with the formula results.

Sometimes, when you copy the contents of a cell, you want to paste just the value and not the underlying formula that is displayed in the formula bar.

For example, you might want to copy the resulting value of a formula to a cell on another worksheet. Or you might want to delete the values that you used in a formula after you copied the resulting value to another cell on the worksheet. Both of these actions cause an invalid cell reference error (#REF!) to appear in the destination cell, because the cells that contain the values that you used in the formula can no longer be referenced.

You can avoid this error by pasting the resulting values of formulas without the formula in destination cells.

  1. On a worksheet, select the cells that contain the resulting values of a formula that you want to copy.

  2. On the Home tab, in the Clipboard group, click Copy Button image .

    Excel Ribbon Image

    Keyboard shortcut: Press CTRL+C.

  3. Select the upper-left cell of the paste area.

    Tip: To move or copy a selection to a different worksheet or workbook, click another worksheet tab or switch to another workbook, and then select the upper-left cell of the paste area

  4. On the Home tab, in the Clipboard group, click Paste Button image , and then click Paste Values, , or press Alt > E > S > V > Enter for Windows, or Option > Command > V > V > Enter on a Mac.

To understand how a complex or nested formula calculates the final result, you can evaluate that formula.

  1. Select the formula you want to evaluate.

  2. Click Formulas > Evaluate Formula.

    Formula Auditing group on the Formula tab

  3. Click Evaluate to examine the value of the underlined reference. The result of the evaluation is shown in italics.

    Evaluate Formula dialog box

  4. If the underlined part of the formula is a reference to another formula, click Step In to show the other formula in the Evaluation box. Click Step Out to go back to the previous cell and formula.

    The Step In button isn't available the second time the reference appears in the formula, or if the formula refers to a cell in another workbook.

  5. Continue until each part of the formula has been evaluated.

    The Evaluate Formula tool won't necessary tell you why your formula is broken, but it can help point out where. This can be a very handy tool in larger formulas where it might otherwise be difficult to find the problem.

    Notes: 

    • Some parts of the IF and CHOOSE functions won't be evaluated, and the #N/A error might appear in the Evaluation box.

    • Blank references are shown as zero values (0) in the Evaluation box.

    • Functions that are recalculated every time the worksheet changes. Those functions, including the RAND, AREAS, INDEX, OFFSET, CELL, INDIRECT, ROWS, COLUMNS, NOW, TODAY, and RANDBETWEEN functions, can cause the Evaluate Formula dialog box to show results that are different from the actual results in the cell on the worksheet.

Need more help?

You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement on Excel User Voice.

See Also

Overview of formulas in Excel

Detect errors in formulas

Excel functions (alphabetical)

Excel functions (by category)

No comments:

Post a Comment