Содержание
- Метод WorksheetFunction.IsNA (Excel)
- Синтаксис
- Параметры
- Возвращаемое значение
- Примечания
- Поддержка и обратная связь
- ISNA – Test if cell is #N/A – Excel, VBA, & Google Sheets
- ISNA Function Overview
- ISNA Function Syntax and Inputs:
- How to use the ISNA Function
- ISERROR, ISERR, and ISNA
- IFNA Function
- Other Logical Functions
- ISNA in Google Sheets
- ISNA Examples in VBA
- If ISNA & IFNA in VLOOKUPs – Excel & Google Sheets
- IFNA in VLOOKUP
- IF ISNA in VLOOKUP
- IFERROR – VLOOKUP
- If ISNA & IFNA in VLOOKUPs – Google Sheets
- Check Excel #N/A using ISNA Function
- Cause of Excel #N/A
- Check Excel #N/A using worksheet formula
- Check Excel #N/A using VBA
- Method 1
- Method 2
- Method 3
- How to Use IF ISNA to Hide VLOOKUP Errors
- The ISNA Formula
- The IF ISNA Formula Combination
- Using IF ISNA with VLOOKUP
- What Excel Does
- Conclusion
- 12 thoughts on “How to Use IF ISNA to Hide VLOOKUP Errors”
Метод WorksheetFunction.IsNA (Excel)
Проверяет тип значения и возвращает значение True или False в зависимости от того, ссылается ли значение на значение ошибки #N/A (значение недоступно).
Синтаксис
expression. IsNA (Arg1)
Выражение Переменная, представляющая объект WorksheetFunction .
Параметры
Имя | Обязательный или необязательный | Тип данных | Описание |
---|---|---|---|
Arg1 | Обязательный | Variant | Value — значение, которое требуется протестировать. Значение может быть пустым (пустая ячейка), ошибкой, логическим, текстовым, числом или ссылочным значением или именем, ссылающимся на любое из этих значений, которое требуется проверить. |
Возвращаемое значение
Boolean
Примечания
Аргументы значений функций IS не преобразуются. Например, в большинстве других функций, где требуется число, текстовое значение 19 преобразуется в число 19. Однако в формуле ISNUMBER(«19») значение 19 не преобразуется из текстового значения, и функция IsNumber возвращает значение False.
Функции IS полезны в формулах для проверки результата вычисления. В сочетании с функцией IF они предоставляют метод для обнаружения ошибок в формулах.
Поддержка и обратная связь
Есть вопросы или отзывы, касающиеся Office VBA или этой статьи? Руководство по другим способам получения поддержки и отправки отзывов см. в статье Поддержка Office VBA и обратная связь.
Источник
ISNA – Test if cell is #N/A – Excel, VBA, & Google Sheets
Download the example workbook
This tutorial demonstrates how to use the Excel ISNA Function in Excel to test if a cell results in #N/A.
ISNA Function Overview
The ISNA Function Test if cell value is #N/A. Returns TRUE or FALSE.
To use the ISNA Excel Worksheet Function, select a cell and type:
(Notice how the formula inputs appear)
ISNA Function Syntax and Inputs:
value – The test value
How to use the ISNA Function
The ISNA Function checks if a calculation results in any error, except the #N/A error.
ISERROR, ISERR, and ISNA
There are two other error checking “is” functions:
- The ISERROR Function returns TRUE for all errors.
- The ISERR Function returns TRUE for all errors except #N/A errors.
The different “is error” functions exist so you can decide what to do about potentially valid #N/A errors.
IFNA Function
Instead of the ISNA Function, you can also use the IFNA Function to do something if an error is detected (instead of simply returning TRUE / FALSE).
Other Logical Functions
Excel / Google Sheets contain many other logical functions to perform other logical tests. Here is a list:
IF / IS Functions |
---|
iferror |
iserror |
isna |
iserr |
isblank |
isnumber |
istext |
isnontext |
isformula |
islogical |
isref |
iseven |
isodd |
ISNA in Google Sheets
The ISNA Function works exactly the same in Google Sheets as in Excel:
ISNA Examples in VBA
You can also use the ISNA function in VBA. Type:
On the sheet below
Executing the following VBA code
will return TRUE for cell A1, which is #N/A, and false for cell B2 which is 5
For the function arguments (value, etc.), you can either enter them directly into the function, or define variables to use instead.
Источник
If ISNA & IFNA in VLOOKUPs – Excel & Google Sheets
This tutorial will demonstrate how to handle VLOOKUP #N/A errors in Excel and Google Sheets. If you have access to the XLOOKUP Function, read our article on handling XLOOKUP errors.
IFNA in VLOOKUP
When you lookup a value with the VLOOKUP Function, if the value is not found, VLOOKUP will return the #N/A error.
You can add the IFNA Function outside of the VLOOKUP, to do something else if the VLOOKUP results in an IFNA error. In this example, we will output “Not found” if the VLOOKUP results in an #N/A error:
Note: The new XLOOKUP Function has built-in error handling. The IFNA Function is not needed!
Another common use of the IFNA Function is to perform a second VLOOKUP if the first VLOOKUP can not find the value. This may be used if a value could be found on one of two sheets; if the value is not found on the first sheet, lookup the value on the second sheet instead.
IF ISNA in VLOOKUP
The IFNA Function was introduced in Excel 2013. Prior to that, you had to use the more complicated IF / ISNA combination:
The ISNA function checks whether the result of the VLOOKUP formula is an #N/A error and returns True or False accordingly. If it is true (i.e., your lookup value is missing from the lookup array), the IF function will return with a message you specify, otherwise it will give you the result of the VLOOKUP.
IFERROR – VLOOKUP
As stated above, the IFNA Function tests if the formula outputs only a #N/A error. Instead, the IFERROR Function can be used to check if ANY error is returned:
Usually it’s better to use IFNA instead of IFERROR, as IFERROR will handle errors that might need your attention.
If ISNA & IFNA in VLOOKUPs – Google Sheets
These formulas work the same in Google Sheets as in Excel.
Источник
Check Excel #N/A using ISNA Function
This Excel tutorial explains how to check Excel #N/A cells using worksheet formula ISNA and VBA Function.
You may also want to read:
Cause of Excel #N/A
#N/A is usually caused by lookup related functions where a value cannot be found in lookup table. Lookup Functions include Vlookup, Match, HLookup, Lookup.
Another common cause is that when you use an Add-In formula, and then send the file to someone who doesn’t have that Add-In. The formula was fine at the time of open the workbook but the formula will turn #N/A once formula is triggered to recalculate.
Check Excel #N/A using worksheet formula
If you want to prevent #N/A in a template with Vlookup formula, you can use IFERROR Function, which captures #N/A as well as other errors. For example
If you try to check if the Cell contains exactly #N/A, use ISNA Function. For example, if A2 contains #N/A then
Check Excel #N/A using VBA
Excel #N/A is extremely annoying in VBA because it probably causes all the subsequent VBA code to fail.
Method 1
To capture Excel #N/A in VBA, the best way is to use the worksheet function ISNA.
Method 2
Alternatively, you can also use Range.Text
Range.Text is what the screen displays, do not use Range.Value because it gets the underlying value.
Method 3
Finally, you can also use On Error Resume Next to skip the error.
Источник
How to Use IF ISNA to Hide VLOOKUP Errors
When writing a series of VLOOKUP formulas, one of the annoying things is having to see the “#N/A” error after Excel has determined a lookup value is not available. While we don’t want to show any values when they are truly unavailable, from a visual design perspective, it’s sometimes better just to show a blank space or a “not found” message. Doing so makes the output look more polished and visually appealing. It also draws less attention to the error values and lets you focus on the values that you have actually found.
The best way to mask “#N/A” errors is by using the IF ISNA formula combination. It’s important to note that you can also use IFERROR to perform the same task, and using IFERROR does require fewer inputs. However, IFERROR is prone to causing errors because it will mask all error types, including the ones that are not “#N/A” errors. Therefore, using IF ISNA is what I recommend.
The ISNA Formula
= ISNA ( value )
The ISNA formula by itself is very simple. All it does is return a “TRUE” or “FALSE” value based on whether or not an input value is equivalent to the “#N/A” error.
For example, if I were to write the ISNA formal to reference one of the “#N/A” values from our previous table, it would return with a “TRUE” result. If I were to write the same formula for another cell, that didn’t have the “#N/A” error, the result would be “FALSE”.
The IF ISNA Formula Combination
= IF ( ISNA ( original formula ) , value_if_error , original formula )
To use the IF ISNA formula combination, you just need to wrap the ISNA formula inside an IF logic condition.
The key to using the IF ISNA formula combination is that you need to put in your original formula twice
Writing your formula twice makes the process take a bit longer, but it is a necessary step to get the formula to work. Below we’ll go through an example with VLOOKUP.
Using IF ISNA with VLOOKUP
Objective : To write a VLOOKUP formula returning multiple values while masking the “#N/A” error whenever it comes up
Step 1 : Start your IF Statement
Step 2 : Start your ISNA Statement
Step 3 : Write your original intended formula
In this case it is a basic VLOOKUP formula. Click here for a tutorial on VLOOKUP.
Step 4 : Close out your ISNA Statement
This is important because you need to add another parenthesis after you’ve finished your VLOOKUP formula. This is a very easy part to miss because your VLOOKUP also ends in a parenthesis. After putting in the parenthesis, close out the logical_test with a comma.
Step 5 : Enter your error condition
The error condition is what we want to show up in place of the “#N/A” error, or the value_if_true within the IF Statement. For this example we’ll use a ” – ” to indicate the value is not available, as for this particular exercise, we’ll essentially assume countries that do not show up in the source data have a value of 0.
Step 6 : Re-enter your original formula (which is your non-error condition)
The easiest way to do this is to copy and paste your original formula over into the last portion of the syntax. Be careful about the number of parentheses you include.
Step 7 : Close out your IF Statement
Finish your IF Statement with a final parenthesis.
Step 8 : Copy your completed formula down
Make sure that you’ve reference locked properly within the VLOOKUP formula. Once that has been confirmed, all you need to do is double click the lower right hand corner of the cell you want to copy down. This final view gives you a picture of what your data set looks like with all of the “#N/A” errors masked.
What Excel Does
The logic for Excel is really simple here. If your VLOOKUP formula returns a “#N/A” error, Excel will show whatever value you input for your error condition. If your VLOOKUP formula does not return a “#N/A” error, then Excel will show whatever value your VLOOKUP was originally intending to return. It’s important to note that Excel looks ONLY for the “#N/A” error, not any other errors that might come up.
Additionally, it should also be noted that this whole process of masking errors also works exactly same with the INDEX MATCH formula as well.
Conclusion
Using IF ISNA to mask errors is a popular trick to improve the visual output of your VLOOKUP summaries. When writing the IF ISNA formula combination, remember that you’ll need to write your original formula twice. You also need to be careful about the number of parentheses you include when writing the formula, as making a mistake here is very easy. (Sometimes Excel will catch parentheses mistakes for you, but sometimes it won’t) Overall, while it does take a bit more time to write than just using the formula itself, doing so is generally worth it if you’re using those outputs for an important meeting or deliverable.
12 thoughts on “How to Use IF ISNA to Hide VLOOKUP Errors”
This is really helpful. Surprising that this info came in handy few days after I was asked to help eliminate the preponderance of the “#N/A” in an excel sheet with data derived from the Vlookup formula. Thanks.
Источник
You can prepare the spreadsheet you like to check as described below and evaluate the special cells containing the IS Functions, it is easy to check them for True
or False
in VBA. Alternatively, you can write your own VBA function as shown below.
There are Excel functions which check cells for special values, for example:
=ISNA(C1)
(assumed that C1 is the cell to check). This will return True
if the cell is #N/A
, otherwise False
.
If you want to show whether a range of cells (say «C1:C17
«) has any cell containing #N/A
or not, it might look sensible to use:
=if(ISNA(C1:C17); "There are #N/A's in one of the cells"; "")
Sadly, this is not the case, it will not work as expected. You can only evaluate a single cell.
However, you can do it indirectly using:
=if(COUNTIF(E1:E17;TRUE)>0; "There are #N/A's in one of the cells"; "")
assuming that each of the cells E1
through E17
contains the ISNA
formulas for each cell to check:
=ISNA(C1)
=ISNA(C2)
...
=ISNA(C17)
You can hide column E
by right-clicking on the column and selecting Hide in Excel’s context menu so the user of your spreadsheet cannot see this column. They can still be accessed and evaluated, even if they are hidden.
In VBA you can pass a range object as RANGE
parameter and evaluate the values individually by using a FOR loop:
Public Function checkCells(Rg As Range) As Boolean
Dim result As Boolean
result = False
For Each r In Rg
If Application.WorksheetFunction.IsNA(r) Then
result = True
Exit For
End If
Next
checkCells = result
End Function
This function uses the IsNA() function internally. It must be placed inside a module, and can then be used inside a spreadsheet like:
=checkCells(A1:E5)
It returns True
, if any cell is #N/A
, otherwise False
. You must save the workbook as macro-enabled workbook (extension XLSM
), and ensure that macros are not disabled.
Excel provides more functions like the above:
ISERROR(), ISERR(), ISBLANK(), ISEVEN(), ISODD(), ISLOGICAL(),
ISNONTEXT(), ISNUMBER(), ISREF(), ISTEXT(), ISPMT()
For example, ISERR()
checks for all cell errors except #N/A
and is useful to detect calculation errors.
All of these functions are described in the built in help of Excel (press F1 and then enter «IS Functions» as search text for an explanation). Some of them can be used inside VBA, some can only be used as a cell macro function.
This Excel tutorial explains how to check Excel #N/A cells using worksheet formula ISNA and VBA Function.
You may also want to read:
Excel IFERROR Function
Cause of Excel #N/A
#N/A is usually caused by lookup related functions where a value cannot be found in lookup table. Lookup Functions include Vlookup, Match, HLookup, Lookup.
Another common cause is that when you use an Add-In formula, and then send the file to someone who doesn’t have that Add-In. The formula was fine at the time of open the workbook but the formula will turn #N/A once formula is triggered to recalculate.
Check Excel #N/A using worksheet formula
If you want to prevent #N/A in a template with Vlookup formula, you can use IFERROR Function, which captures #N/A as well as other errors. For example
=IFERROR(VLOOKUP(D3,$A$3:$B$7,2,0),”Not found”)
If you try to check if the Cell contains exactly #N/A, use ISNA Function. For example, if A2 contains #N/A then
=ISNA(A2) returns TRUE
Excel #N/A is extremely annoying in VBA because it probably causes all the subsequent VBA code to fail.
Method 1
To capture Excel #N/A in VBA, the best way is to use the worksheet function ISNA.
For example
Application.Worksheetfunction.ISNA(A2)
Method 2
Alternatively, you can also use Range.Text
Range("A2").Text = "#N/A"
Range.Text is what the screen displays, do not use Range.Value because it gets the underlying value.
Method 3
Finally, you can also use On Error Resume Next to skip the error.
Outbound References
https://support.office.com/en-us/article/Start-the-Power-Pivot-in-Microsoft-Excel-add-in-a891a66d-36e3-43fc-81e8-fc4798f39ea8?ui=en-US&rs=en-US&ad=US
When writing a series of VLOOKUP formulas, one of the annoying things is having to see the “#N/A” error after Excel has determined a lookup value is not available. While we don’t want to show any values when they are truly unavailable, from a visual design perspective, it’s sometimes better just to show a blank space or a “not found” message. Doing so makes the output look more polished and visually appealing. It also draws less attention to the error values and lets you focus on the values that you have actually found.
The best way to mask “#N/A” errors is by using the IF ISNA formula combination. It’s important to note that you can also use IFERROR to perform the same task, and using IFERROR does require fewer inputs. However, IFERROR is prone to causing errors because it will mask all error types, including the ones that are not “#N/A” errors. Therefore, using IF ISNA is what I recommend.
The ISNA Formula
= ISNA ( value )
The ISNA formula by itself is very simple. All it does is return a “TRUE” or “FALSE” value based on whether or not an input value is equivalent to the “#N/A” error.
For example, if I were to write the ISNA formal to reference one of the “#N/A” values from our previous table, it would return with a “TRUE” result. If I were to write the same formula for another cell, that didn’t have the “#N/A” error, the result would be “FALSE”.
The IF ISNA Formula Combination
= IF ( ISNA ( original formula ) , value_if_error , original formula )
To use the IF ISNA formula combination, you just need to wrap the ISNA formula inside an IF logic condition.
The key to using the IF ISNA formula combination is that you need to put in your original formula twice
Writing your formula twice makes the process take a bit longer, but it is a necessary step to get the formula to work. Below we’ll go through an example with VLOOKUP.
Using IF ISNA with VLOOKUP
Objective: To write a VLOOKUP formula returning multiple values while masking the “#N/A” error whenever it comes up
Step 1: Start your IF Statement
Step 2: Start your ISNA Statement
Step 3: Write your original intended formula
In this case it is a basic VLOOKUP formula. Click here for a tutorial on VLOOKUP.
Step 4: Close out your ISNA Statement
This is important because you need to add another parenthesis after you’ve finished your VLOOKUP formula. This is a very easy part to miss because your VLOOKUP also ends in a parenthesis. After putting in the parenthesis, close out the logical_test with a comma.
Step 5: Enter your error condition
The error condition is what we want to show up in place of the “#N/A” error, or the value_if_true within the IF Statement. For this example we’ll use a ” – ” to indicate the value is not available, as for this particular exercise, we’ll essentially assume countries that do not show up in the source data have a value of 0.
Step 6: Re-enter your original formula (which is your non-error condition)
The easiest way to do this is to copy and paste your original formula over into the last portion of the syntax. Be careful about the number of parentheses you include.
Step 7: Close out your IF Statement
Finish your IF Statement with a final parenthesis.
Step 8: Copy your completed formula down
Make sure that you’ve reference locked properly within the VLOOKUP formula. Once that has been confirmed, all you need to do is double click the lower right hand corner of the cell you want to copy down. This final view gives you a picture of what your data set looks like with all of the “#N/A” errors masked.
What Excel Does
The logic for Excel is really simple here. If your VLOOKUP formula returns a “#N/A” error, Excel will show whatever value you input for your error condition. If your VLOOKUP formula does not return a “#N/A” error, then Excel will show whatever value your VLOOKUP was originally intending to return. It’s important to note that Excel looks ONLY for the “#N/A” error, not any other errors that might come up.
Additionally, it should also be noted that this whole process of masking errors also works exactly same with the INDEX MATCH formula as well.
Conclusion
Using IF ISNA to mask errors is a popular trick to improve the visual output of your VLOOKUP summaries. When writing the IF ISNA formula combination, remember that you’ll need to write your original formula twice. You also need to be careful about the number of parentheses you include when writing the formula, as making a mistake here is very easy. (Sometimes Excel will catch parentheses mistakes for you, but sometimes it won’t) Overall, while it does take a bit more time to write than just using the formula itself, doing so is generally worth it if you’re using those outputs for an important meeting or deliverable.