How to use the NA function
What is the NA function?
The NA() function returns the error value #N/A meaning "value is not available". Use the NA() function to fill empty cells to avoid including empty cells in your calculations. Use the ISNA or IFNA function to identify #N/A errors.
Table of Contents
1. Introduction
What is the #N/A error value?
The #N/A error occurs when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
The NA function lets you return the #N/A error in any formula you like, you can for instance use the IF function and a logical expression to determine when the error should occur.
Related #N/A functions
Excel Function | Description |
---|---|
NA() | Returns the #N/A error value |
IFNA(value, value_if_na) | Returns value_if_na if value is #N/A, otherwise returns value |
ISNA(value) | Returns TRUE if value is #N/A, FALSE otherwise |
ISERR(value) | Returns TRUE if value is any error except #N/A, otherwise FALSE |
ISERROR(value) | Returns TRUE if value is any error value, FALSE otherwise |
IFERROR(value, value_if_error) | Returns value_if_error if value is any error, otherwise returns value |
2. Syntax
NA()
The NA() function has no arguments.
3. Example 1
This example demonstrates the most basic way to use the NA function. The image above shows the NA function in cell B3, the formula in cell B3 is displayed in cell C3.
Formula in cell B3:
The output in cell B3 is an #N/A error which means "Not Avaliable". Some Excel functions return the #N/A error value if a particular value is not found like:
- VLOOKUP function
- MATCH function
4. Example 2
This example shows how to return the #N/A error if a VLOOKUP function returns an empty value. On the left (columns A and B):
- A list of office supplies (Text) with their corresponding prices (Price). Items include Binder, Paper, Pen, Eraser, Pencil, Note book, Scissor, Labels, Tape, and Envelopes
- Prices range from $1.70 to $7.50 and some cells are empty for example cells C5, C8, and C11.
Formula in cell F3:
The formula in cell F3 returns #N/A error because the lookup value in cell E3 "Tape" is found in column B, however the corresponding value in column C on the same row is empty.
This formula does the following:
- Attempts to look up the value in E3 (Tape) in the range B3:C12
- If the lookup returns an empty string, it returns NA() (Not Available)
- Otherwise, it returns the result of the VLOOKUP
This demonstrates how to use the NA() function in conjunction with VLOOKUP to handle missing data or items not found in the lookup range.
Explaining formula in cell F3
Step 1 - Evaluate VLOOKUP
The VLOOKUP function lets you search the leftmost column for a value and return another value on the same row in a column you specify.
Function syntax: VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
VLOOKUP(E3,B3:C12,2,FALSE)
returns "", however, Excel shows 0 (zero) meaning the cell is empty.
Step 2 - Compare output to nothing ""
The equal sign is a logical operator that lets you compare values. This example shows how to check if the result of the VLOOKUP function is empty.
VLOOKUP(E3,B3:C12,2,FALSE)=""
becomes
""=""
and returns TRUE.
What is a Boolean value?
A Boolean value in Excel is a value that can only be TRUE or FALSE. It represents binary logic and is the result of a logical expression using logical operators or a result of a few Excel functions.
Mastering Boolean logic and logical expressions is key to manipulating data and controlling workflow in Excel.
Step 3 - Perform logic based on outcome
The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.
Function syntax: IF(logical_test, [value_if_true], [value_if_false])
IF(VLOOKUP(E3,B3:C12,2,FALSE)="",NA(),VLOOKUP(E3,B3:C12,2,FALSE))
becomes
IF(TRUE,NA(),VLOOKUP(E3,B3:C12,2,FALSE))
and "#N/A" is returned.
5. Example 3
The image above shows an Excel spreadsheet with monthly price data in columns B and C, and corresponding line charts. The "Hidden and Empty Cell Settings" dialog box demonstrates different ways to handle empty cells and #N/A values in charts. The chart above shows gaps between data points.
Here is how to access the "Hidden and Empty Cell Settings" dialog box:
- Press with right mouse button on on the chart. A popup menu appears.
- Press with left mouse button on "Select Data...". A dialog box appears named "Select Data Source".
- Press with left mouse button on the "Hidden and Empty Cells" button located at the bottom left corner of the dialog box.
The "Hidden and Empty Cells" dialog box appears.
Press with left mouse button on the OK button to apply changes.
"Hidden and Empty Cells" dialog box has these settings in order to get the outcome shown in the image above:
- Show empty cells as: Gaps
- Check box "Show #N/A as an empty cell": Enabled
- Check box "Show data in hidden rows and columns": Disabled
Excel users can take advantage of the #N/A error and NA() function when working with charts in several ways:
- Controlling data visibility: By using #N/A or the NA() function in cells where data is missing or shouldn't be plotted, users can control which points appear on the chart. This is useful for showing gaps in data or excluding certain periods from visualization.
- Flexible chart appearance: The "Hidden and Empty Cell Settings" dialog allows users to choose how #N/A values are displayed in charts:
- As gaps (Image above): Creates breaks in the line chart where data is missing.
- As zero (Image 2): Plots #N/A values at zero, which can be misleading but sometimes desired. See the image below.
- Connected with lines (Image 3): Draws lines between known data points, ignoring #N/A values. See the last image below in this section.
- Data integrity: Using #N/A or NA() clearly indicates missing data, unlike leaving cells blank or using zero which could be misinterpreted.
- Dynamic charts: When combined with formulas, #N/A can be used to create dynamic charts that show or hide data based on certain conditions.
- Error handling: In complex calculations, NA() can be used to propagate errors or unknown values through a series of formulas, affecting the chart only where truly necessary.
By understanding these options you can create more accurate charts that better represent their data including any gaps or uncertainties.
The image above shows a line chart in the bottom-right corner of the image where #N/A values are plotted at zero. "Hidden and Empty Cells" dialog box above the line chart demonstrates the settings that produce this outcome.
"Hidden and Empty Cells" dialog box has these settings:
- Show empty cells as: Zero
- Check box "Show #N/A as an empty cell": Enabled
- Check box "Show data in hidden rows and columns": Disabled
The image above shows a line chart in the bottom-right corner of the image where #N/A values are ignored and the remaining values are connected with a line. "Hidden and Empty Cells" dialog box above the line chart demonstrates the settings that produce this outcome.
"Hidden and Empty Cells" dialog box has these settings:
- Show empty cells as: Connect data points with line
- Check box "Show #N/A as an empty cell": Enabled
- Check box "Show data in hidden rows and columns": Disabled
6. How to enter the NA function in all empty cells at once?
Here is how to enter the NA() function in all empty cells in a given cell range. I am going to show you how to enter the NA() function in all empty cells in cell range C3:C8 in this example based on the image above:
- Select cell range C3:C12
- Press function key F5, a dialog box appears.
- Press with left mouse button on the "Special.." button, another dialog box appears.
- Press with left mouse button on "Blanks" to select it.
- Press with left mouse button on the "OK" button.
The image shows all empty cells selected.
- Press with left mouse button on in the "Formula bar".
- Type =NA()
- Press and hold the CTRL key.
- Press Enter once.
- Release the CTRL key.
The image above displays the final result, all empty cells are now populated with a #N/A error.
7. Function not working
The NA function returns a #NAME? error if you misspell the function name. It does not propagate errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error. The function has no arguments, in other words, it is impossible to propagate
7.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
7.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows =NAA() converted to hard-coded value using the F9 key which displays #NAME? error. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
7.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
'NA' function examples
This article demonstrates a formula that allows you to search a data set using any number of conditions, however, one […]
Functions in 'Information' category
The NA function function is one of 19 functions in the 'Information' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form