How to suppress #VALUE and other errors without IFs

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,532
Office Version
  1. 365
Platform
  1. Windows
I have several tables that show how to use various probability and statistical functions. Depending on the initial conditions, many of them change not only the results but the number of valid results. This table intended to illustrate the Binom.Dist function is a good example.

1632975516214.png


It's set up to show the results for a total of 5 trials. But suppose I want to see resutls for 3 trials. If I just change T to 3, I will get a bunch of #NUM errors for those cells with parameters out of range. And the Sum of the P(N) values also fails.

1632975347452.png


I "solved" this problem by adding IF functions to each equation that test for valid parameters.

1632975647463.png


The table looks nicer, but the equations do not. And the whole purpose of the sheet was to help me remember how to use this function. My other option was to put everything in a UDF that would check for valid parameters and then either return a value or "". But then the function I am trying to illustrate is even less obvious buried in code.

I looked into custom and conditional formats, but they only change the appearance of the cell. The data would still be an error, which would cause any sums or averages to fail.

Please let me know if there is a better way.

I would post the mini sheet, but I have some unlimited ranges, which causes it to hang.
 

Attachments

  • 1632975256507.png
    1632975256507.png
    42.7 KB · Views: 9

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
At the moment you are capturing very specific errors and returning "".
If you are happy return "" for all errors you could replace the condition part
=IF(condition,calculation,"")
with
=IFERROR(calculation,"")
 
Upvote 0
Solution
At the moment you are capturing very specific errors and returning "".
If you are happy return "" for all errors you could replace the condition part
=IF(condition,calculation,"")
with
=IFERROR(calculation,"")
Very nice. That has a couple of advantages:
  1. It's simpler, so the target formulas are less obscured.
  2. It relieves me of the need to figure out what the error conditions are.
  3. And that eliminates one source of errors -- me. The values in G11 & H11 were missing in the tables above because I miscoded the error condition as "@N<T". It should have been "@N<=T", proving that Binom.Dist is better at detecting errors than I am.
Here's the improved table with the new values shown in yellow.

1632982972934.png


I'm going to mark this as solved, because I doubt anyone has a better solution. If they do, I'll change it.

Thanks for the help.
 
Upvote 0
Nothing wrong with Alex's solution, but with 365 you could also do:

ABC
1p50%
2T3
3
4NP(N)etc
5012.5%
6137.5%
7237.5%
8312.5%
9
Sheet1
Cell Formulas
RangeFormula
A5:A8A5=N
B5:B8B5=BINOM.DIST(N,T,p,)
Dynamic array formulas.
Named Ranges
NameRefers ToCells
p=Sheet1!$B$1B5
T=Sheet1!$B$2A5:B5

where N: =SEQUENCE(T+1,,0)
 
Upvote 0
I use this simple macro add iferror to existing formula:
VBA Code:
Sub addiferror()
cform = ActiveCell.Formula
cform2 = Mid(cform, 2)
'cform3 = "=iferror(" & cform2 & ","""")"
cform3 = "=iferror(" & cform2 & ",FALSE)"

 ActiveCell.Formula = cform3
End Sub
You can change it to get FALSE or "" as required
 
Upvote 0
Nothing wrong with Alex's solution, but with 365 you could also do:

Wow! That looks like it could be powerful. But I'm going to need to study it. I was able to generate an array of values for N. but I couldn't see how you got the P(N) column. I tried naming the Sequence array and using that as an argument, but that didn't work.

Do you know of a good tutorial on this? I checked several YouTube videos, but they are all very primitive. They just show you how to generate various lists.

Thanks
 
Upvote 0
I used Name Manager to create a new name N:

NM1.png


Alternatives:

ABCD
1p50%
2T3
3
4NP(N)P(N)P(N)
5012.5%12.5%12.5%
6137.5%37.5%37.5%
7237.5%37.5%37.5%
8312.5%12.5%12.5%
Sheet1
Cell Formulas
RangeFormula
A5:A8A5=N
B5:B8B5=BINOM.DIST(N,T,p,)
C5:C8C5=BINOM.DIST(A5#,T,p,)
D5:D8D5=BINOM.DIST(AnotherN,T,p,)
Dynamic array formulas.
Named Ranges
NameRefers ToCells
AnotherN=Sheet1!$A$5#C5:D5
p=Sheet1!$B$1B5:D5
T=Sheet1!$B$2A5:D5


NM3.png


If you don't mind spending $5, I can recommend the house brand: Excel Dynamic Arrays Straight to the Point 2nd Edition

I'm not an Excel video watcher, but perhaps others can suggest good link(s) for you?
 
Upvote 0
I use this simple macro add iferror to existing formula:
VBA Code:
Sub addiferror()
cform = ActiveCell.Formula
cform2 = Mid(cform, 2)
'cform3 = "=iferror(" & cform2 & ","""")"
cform3 = "=iferror(" & cform2 & ",FALSE)"

 ActiveCell.Formula = cform3
End Sub
You can change it to get FALSE or "" as required

I'll have to study that one, too. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top