+ Reply to Thread
Results 1 to 6 of 6

Same function two times in one formula?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-14-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Same function two times in one formula?

    Can anyone explain how Excel treats function calls like:

    =IF(ISNA(VLOOKUP(100,MyRange,2,False)),"",VLOOKUP(100,MyRange,2,False))

    A colleague says that Excel "intelligently" figures out that the two vlookup calls are the same, so it does only one vlookup call in order to return the result of this formula (instead of calling vlookup twice). Is this true? And what are the limitations of this call handling?

    I know I should use IFERROR(vlookup..) here. But what if I have an outside function like BDP(...) which returns the _text_ "#N/A N A" (and isserr doesn't work)? Should I make a User-defined function to avoid making the call twice?

    Thanks!

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Same function two times in one formula?

    Hi schlesinger,

    The IfError was introduced in 2007 Excel. Your way of doing it is how we had to do it back in 2003 and earlier Excel.

    I wonder how your freind knows how Excel deals with your formula. Find the Evaluate feature and see how Excel really does deal with it. I'd be thinking it would need to do the VLookup twice if it wasn't an error on the first try.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Valued Forum Contributor scottylad2's Avatar
    Join Date
    09-03-2010
    Location
    edinburgh
    MS-Off Ver
    Office 2007 Prof & Office 2010 Student Edition
    Posts
    629

    Re: Same function two times in one formula?

    IF(ISNA(VLOOKUP(100,MyRange,2,False)),"",VLOOKUP(100,MyRange,2,False))

    You can break this formula down quite easy to state what it does, it says if the first Vlookup returns #NA then your answer will be left blank, in order for that to happen excel has to do the first Vlookup and if #NA is the result then there's no need for it to do the second. if there's no #NA then Vlookup number 2 will be done, the first one is only testing for #NA

    you could change the if to reflect you want tha #NA displayed, which would work only on that error but you could have a not available in either your lookup cell or your lookup table. you could use

    =IF(ISNA(VLOOKUP(100,MyRange,2,False)),"#NA",VLOOKUP(100,MyRange,2,False))
    Windows 7 using Office 2007 & 2010

    Remember your [ code ] [ /code ] tags, makes reading soooo much easier

  4. #4
    Registered User
    Join Date
    08-14-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Same function two times in one formula?

    hey marvin, thanks, i checked out the evaluate formula. you are right excel does seem to evaluate the vlookups separately, going as far as to evaluate individual references separately. (like if it was vlookup(a5, myrange, 0) it would evaluate the a5 twice, not once.) it seems inefficient.

    scottylad2, i appreciate your help but my question was asking whether excel treats the vlookup as two separate calls or as one call, not what the example does--i understand what the example does, obviously.

  5. #5
    Valued Forum Contributor scottylad2's Avatar
    Join Date
    09-03-2010
    Location
    edinburgh
    MS-Off Ver
    Office 2007 Prof & Office 2010 Student Edition
    Posts
    629

    Re: Same function two times in one formula?

    Quote Originally Posted by schlesinger View Post

    scottylad2, i appreciate your help but my question was asking whether excel treats the vlookup as two separate calls or as one call, not what the example does--i understand what the example does, obviously.
    Wrapped up in the If, it won't do the vlookup twice per se. It will evaluate the first part, and if it returns TRUE then there would be no reason to do the second one. If False then the second Vlookup would be evaluated on its own content with the first one being ignored. Obviously you knew that though

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Same function two times in one formula?

    it probably doesn't matter as long as you don't use hundreds of vlookups
    but read here
    http://www.decisionmodels.com/optspeede.htm
    see the section
    Unsorted Data with Missing Values.
    Last edited by martindwilson; 08-21-2011 at 05:20 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1