+ Reply to Thread
Results 1 to 4 of 4

Formula to calculate result whilst avoiding errors is too long!

Hybrid View

  1. #1
    Registered User
    Join Date
    03-21-2008
    Posts
    52

    Formula to calculate result whilst avoiding errors is too long!

    Konnichi wa comrades,

    I have a formula I've been using for a long time which uses VLOOKUP to find results based on various reference cells, and then adds them up. To avoid errors caused by VLOOKUP not finding anything for one of the references I have also used ISERROR. The formula returns a blank if the calculation returns a zero.

    I now need to bring further references in to the calculation but, using the format I have been, the formula is now too long. Here is my extensive formula:

     =IF((SUM((IF(ISERROR(VLOOKUP($K6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($K6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($L6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($L6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($M6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($M6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($N6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($N6,'1st'!$B$4:$Q$340,16,FALSE)))))((IF(ISERROR(VLOOKUP($O6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($O6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($P6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($P6,'1st'!$B$4:$Q$340,16,FALSE))))))=0,"",(SUM((IF(ISERROR(VLOOKUP($K6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($K6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($L6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($L6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($M6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($M6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($N6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($N6,'1st'!$B$4:$Q$340,16,FALSE))))))+((IF(ISERROR(VLOOKUP($O6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($O6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($P6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($P6,'1st'!$B$4:$Q$340,16,FALSE))))))
    Can anybody help me chop this beast down to size? It may be easier if we look at a version referencing less cells to see if we can shorten this and then factor the changes in to the above. Here is a version which refers to just 2 cells:

    =IF((SUM((IF(ISERROR(VLOOKUP($F6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($F6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($G6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($G6,'1st'!$B$4:$Q$340,16,FALSE))))))=0,"",(SUM((IF(ISERROR(VLOOKUP($F6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($F6,'1st'!$B$4:$Q$340,16,FALSE)))))+((IF(ISERROR(VLOOKUP($G6,'1st'!$B$4:$Q$340,16,)),"0",(VLOOKUP($G6,'1st'!$B$4:$Q$340,16,FALSE)))))))
    Thanks in advance, Monkdelafunk
    Last edited by monkdelafunk; 01-22-2010 at 10:09 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Formula to calculate result whilst avoiding errors is too long!

    Perhaps

    =SUMPRODUCT(SUMIF('1st'!$B$4:$B$340,K6:P6,'1st'!$Q$4:$Q$340))
    though the first formula you list is hard to follow I've assumed you're summing col Q on 1st sheet where value in B is one of those values specified in K6:P6

  3. #3
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Formula to calculate result whilst avoiding errors is too long!

    Try this for your second formula.

    =SUMPRODUCT((F6='1st'!$B$4:$B$340)+(G6='1st'!$B$4:$B$340),'1st'!$Q$4:$Q$340)

    Assumption
    If F6 is found in B4:B340 then return the value in Q
    If G6 is found in B4:B340 then return the value in Q
    sum these two
    Last edited by rwgrietveld; 01-22-2010 at 10:03 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  4. #4
    Registered User
    Join Date
    03-21-2008
    Posts
    52

    Re: Formula to calculate result whilst avoiding errors is too long!

    Well, well, well. It transpires I am still very much a novice in the heady world of formula writing!

    I've added an IF statement to return a blank if the result is zero and, hey presto, exactly what I'm after without getting repetitive strain injury from typing it!

    Thanks DonkeyOte, and well done for having my favourite user name.

+ 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