the OR function always trips me up - excel

I've always had trouble with this one over the years! I don't seem able to get the OR function in Excel to work.
In my model, the cell E46 should contain either a valid Postcode or the value "none". Unfortunately I have also encountered a "#value" in E46 so have written the following formula to trap this error and return "None" if encountered:
=IF(OR(E46="None",ISERROR(E46)),"None",VLOOKUP(E46, List,2,FALSE))
Trouble is, I still get #value returned by this formula when E46 contains #value even though I think I am trapping it!
All the help texts suggest I have written the formula correctly – I cannot see what I am doing wrong. Any helpful suggestions gratefully received.

You can't use OR when there might be an error in there (because the OR function will give an error in that case - from E46="None" part), try trapping the error first with nested IFs, e.g.
=IF(ISERROR(E46),"None",IF(E46="None",E46,VLOOKUP(E46, List,2,FALSE)))
You'd still get an error if E46 isn't in List......
If you have Excel 2007 or greater you can use IFERROR like
=IFERROR(IF(E46="None",E46,VLOOKUP(E46, List,2,FALSE)),"None")

Related

Cell-Address with an IF Statement

I've been using =Cell("address",... to error check formulas I'm making to create a database and it's been working pretty well until I tried to scale up my index match formulas with some if statements.
I've narrowed the issue down to where I believe it's working as intended as long as the first statement in the if statement is true, yet if the calculation goes past that (even if the original formula is fine and returns a value) it will come back with #VALUE!.
EDIT: To be clear, the formula used above returns values without issue when not using the CELL-ADDRESS function involved. The formula also returns values when split up outside the IF-Statement.
I2=Valid
=CELL("address",IF($I$2="Valid",INDEX($I$2:$J$6,MATCH($U$1,$H$2:$H$6,0),MATCH($V$1,$I$1:$J$1,0)),IF($I$2="Invalid",INDEX($I$2:$J$6,MATCH($W$1,$H$2:$H$6,0),MATCH($V$1,$I$1:$J$1,0)),"Error")))
$I$2 is returned in the cell
I2=Invalid
=IF($I$2="Valid",INDEX($I$2:$J$6,MATCH($U$1,$H$2:$H$6,0),MATCH($V$1,$I$1:$J$1,0)),IF($I$2="Invalid",INDEX($I$2:$J$6,MATCH($W$1,$H$2:$H$6,0),MATCH($V$1,$I$1:$J$1,0)),"Error"))
#VALUE! is returned
Can anyone offer a fix for this or explain why it's happening and how to avoid it?
Any help would be appreciated.
Thanks!

Using error handling within a formula which has multiple parts

I'm trying to implement error handling as part of the following formula, to account for cells in each range which simply don't have a value and return a "#NUM!" error:
{=SUMPRODUCT(R2:T2,U2:W2)/SUM(R2:T2)}
So far I've had some luck using IF and ISNUMBER combined (as shown below) when splitting up the main formula above, but I'm struggling when it comes to implementing it for each section/cell range. My attempt:
{=SUMPRODUCT(IF(ISNUMBER(R3:T3),R3:T3))}
Any help would be greatly appreciated!
Your original formula, without error handling, can be entered normally. It doesn't need Ctl+Shift+Enter. Nor can it produce a #NUM error because both the SUM() and SUMPRODUCT() functions interpret non-numeric values as zero. Therefore, if you get a #NUM error that error would be created by formulas in the range R2:W2. You should introduce error handling there, not in the formula we are looking at here.
The formula here - that is your first, original formula - will produce a Division by Zero error if SUM(R2:T2) equals zero. =IFERROR(SUMPRODUCT(R2:T2,U2:W2)/SUM(R2:T2),0) would return zero in case of such an error. You can modify the formula to something like =IFERROR(SUMPRODUCT(R2:T2,U2:W2)/SUM(R2:T2),"ERROR") if you prefer.
This kind of error handler would take effect also if an unhandled error is inherited from R2:W2. My recommendation is to handle errors where they occur but if you wish for a more specific error handler in the formula we are looking at here, the formula below would let imported #NUM errors pass and only handle #DIV BY ZERO errors produced by this formula.
=SUMPRODUCT(R3:T3,U3:W3)/IF(SUM(R3:T3),SUM(R3:T3),1)
This formula divides the result of the SUMPRODUCT() function by 1 if SUM(R3:T3) equals zero. This returns a result from the formula of 0 because the SUMPRODUCT part would return zero (unless it inherits a #NUM error).

countifs named range gives #VALUE error

I just replaced the values within a formula and now it's value errors all the way, I'm not sure why:
old formula: =COUNTIFS(Cat,M$3,Sup,$B45)
new formula: =COUNTIFS(Cat,M$3,Client,$B45)
simply doing =COUNTIFS(Cat,M$3) and =COUNTIFS(Client,$B45) works, but I obviously need the common count of the two!
=SUMPRODUCT(COUNTIFS(Cat,M$3,Client,$B45)) also gives #value error
The named ranges work, so what is the problem?
The solution lies in making sure that the two ranges are of same length, as mentioned in the comment.
I'm hoping to mark this as complete, since voting to close did not work out, but this question has been resolved.

how to say "If the formula in this named range returns an error, then the value is one, else zero" in Excel

Hi guys i would like to ask a very simple question,how to say "If the formula in this named range returns an error, then the value is one, else zero" in Excel?
I was thinking like "IF (A1:A200 Returns an Error, 1, 0).
I attach a screenshot so you guys could see what i am trying to do, the cells in red are the ones that contains error.
Thanks guys, your help would be very appreciated.
You can use SUMPRODUCT and ISERR (or ISERROR, see note below on the difference between these) functions. This will count the number of errors in the range:
=SUMPRODUCT(--ISERR(A1:A200))
Then, wrap it in an IF, like:
=IF(SUMPRODUCT(--ISERR(A1:A200))>0,1,0)
HERE is a good explanation of how the functions work.
NOTE: ISERR counts all errors except #N/A. If you want to also count #N/A, use the ISERROR function instead of ISERR.

Appear #VALUE! in excel vba

I faced this problem. When I want to retrieve the value in a cell with the value of #VALUE!, I got the error2015. May I know how to solve this kind of problem with some example? Thanks so much.
This is not a problem. The cell actually contains a Variant/Error, so there you have it.
The same value you can get by calling CVErr(2015).
You might use the .Text property instead of .Value to get the actual text '#VALUE!', but then a) you will not be able to know if it's an error or someone just put mere text '#VALUE!' in the cell, and b) the returned text will be different in different regional versions of Excel.
If you are checking cells for errors, the right thing to do is to call IsError(.Value), and if True, check exactly which error.

Resources