MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 16th, 2005, 10:55 AM   #1
AlphaQuant
 
Join Date: Apr 2005
Posts: 9
Default How to do =IF(ISERROR(long formula),0,value) efficiently?

Hi

I want a way to test a long formula to see if it is an error. If yes then return zero else return the value of the formula. The key is not to have to repeat the formula as it might be extremely long and take a relatively long time to computer. Essentially what I want is

=IF(ISERROR(long formula),0,long formula value)

This is a situation I face all the time and everytime I cannot believe that Excel doesn't have a built-in function for this. There are of course workarounds but each has its problems. Some workarounds I can think of are:
(i) Placing formula in a separate cell. You can then just test the cell value against the error condition. PROBLEM: I can't apply this to large tables of numbers.

(ii) Repeating the formula in else condition of if statement. PROBLEM: Cumbersome and doubles the execution time of code when it's really not necessary. Thus also unsuitable for applying to large spreadsheets.

(iii) Writing custom vba user defined function. This is probably what I'll have to do, however; PROBLEM: I'm told UDFs are also slow so this is also not ideal for large workbooks. Also you either have to rewrite the function in every workbook you use it in or put it in a standard XLA but then the spreadsheet might not run on colleagues machines who don't have the XLA installed.

Does anyone know of any workarounds using only worksheet functions? Any comments on the issue in general?
AlphaQuant is offline   Reply With Quote
Old May 16th, 2005, 10:59 AM   #2
fairwinds
MrExcel MVP
 
fairwinds's Avatar
 
Join Date: May 2003
Posts: 8,474
Default

Hi,

If your long formula returns a number, maybe you could do like this?

=LOOKUP(9.99999999999999E+307,CHOOSE({1,2},0,longformula))
__________________
"Fair Winds and Following Seas"
fairwinds is offline   Reply With Quote
Old May 16th, 2005, 11:18 AM   #3
AlphaQuant
 
Join Date: Apr 2005
Posts: 9
Default

Thanks, that works.

At first I was a bit confused why you used CHOOSE but it seems this is to trick Excel to return an array because when I tried =LOOKUP(9e307,{0,longformula}) it gave an error.

It works in my case as I have only positive numbers but I suspect the formula will have to be amended if my longformula returned positive and negative values.

This has given me something to work with though, so thank you very much.
AlphaQuant is offline   Reply With Quote
Old May 16th, 2005, 11:21 AM   #4
fairwinds
MrExcel MVP
 
fairwinds's Avatar
 
Join Date: May 2003
Posts: 8,474
Default

No you do not need to alter the formula.

It will return the "longformula" result as long as it is a numerical value regardless negative or positive.


But you are right about CHOOSE returning an array, when fed an array constant as first argument.
__________________
"Fair Winds and Following Seas"
fairwinds is offline   Reply With Quote
Old May 16th, 2005, 04:47 PM   #5
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 42,625
Default

If you invoke ISERROR very often...

=IF(ISNUMBER(SETV(Calculation)),GETV(),0)

would also have a significant impact on speed.

SETV/GETV are supplied by Longre's morefunc add-in.
__________________
Microsoft MVP - Excel
Aladin Akyurek is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 05:27 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2010 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes