+ Reply to Thread
Results 1 to 7 of 7

Simplifying my formula

  1. #1
    Forum Contributor
    Join Date
    05-07-2007
    Location
    Singapore
    MS-Off Ver
    2006/2016
    Posts
    170

    Question Simplifying my formula

    Hi all

    i currently have this code for my excel spreadsheet it is to count the instances where i want to find out how many types of red apples i have, so i wrote the following function.

    =SUM((TRIM(RD!B2:RD!B590)="Apples")*(TRIM(RD!I2:RD!I590)="Red")
    ]

    this is where column B is the type of fruit and column I is the fruit's colour

    so i was wondering if there is a way to simplify the fomula where i define the various ranges so that i can simplify the fomula to something like

    =SUM((TRIM(A)="Apples")*(TRIM(B)="Red")
    ]
    where A=RD!B2:RD!B590 and B=RD!I2:RD!I590

    i tried using the Define->name function (where i set the range as the name) but i couldnt get it to work.

    Any suggestions?

  2. #2
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    Do you enter this formula as array (i-e by pressing Ctrl+Shift+Enter)?

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by lordfa9
    Hi all

    i currently have this code for my excel spreadsheet it is to count the instances where i want to find out how many types of red apples i have, so i wrote the following function.

    ]

    this is where column B is the type of fruit and column I is the fruit's colour

    so i was wondering if there is a way to simplify the fomula where i define the various ranges so that i can simplify the fomula to something like

    ]
    where A=RD!B2:RD!B590 and B=RD!I2:RD!I590

    i tried using the Define->name function (where i set the range as the name) but i couldnt get it to work.

    Any suggestions?

    Try Sumproduct():

    =SUMPRODUCT(--(TRIM(A)="Apples"),--(TRIM(B)="Red"))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Forum Contributor
    Join Date
    05-07-2007
    Location
    Singapore
    MS-Off Ver
    2006/2016
    Posts
    170
    ok so what i did was to 1st define the name of the range. So i went to the name->define and set the following as I
    =Fruits!$I$2:Fruits!$I$590

    The i used the following formula:
    =SUM(TRIM(I)="Red")

    after typing i set it as an array using Ctrl+Shift+Enter

    The answer the formula gave me is 0 even though there is data in the worksheet that meets the criteria.

    I tried using the SUMPRODUCT function and still it gave me 0

  5. #5
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    Quote Originally Posted by lordfa9
    ok so what i did was to 1st define the name of the range. So i went to the name->define and set the following as I
    =Fruits!$I$2:Fruits!$I$590

    The i used the following formula:
    =SUM(TRIM(I)="Red")

    after typing i set it as an array using Ctrl+Shift+Enter

    The answer the formula gave me is 0 even though there is data in the worksheet that meets the criteria.

    I tried using the SUMPRODUCT function and still it gave me 0
    Please attach a sample file.

  6. #6
    Forum Contributor
    Join Date
    05-07-2007
    Location
    Singapore
    MS-Off Ver
    2006/2016
    Posts
    170
    somehow i managed to get it to work when i undid everything and tried again.

    Not sure why though might be some typos in the formula, most likely the brackets
    Last edited by lordfa9; 05-08-2007 at 09:34 PM.

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    This formula

    =SUM(TRIM(I)="Red")

    won't work as written because you are trying to sum TRUEs and FALSEs, you need to coerce to numbers (TRUE=1, FALSE=0) to make this work, similar to the SUMPRODUCT formula quoted, e.g.

    =SUM((TRIM(I)="Red")+0)

    confirmed with CTRL+SHIFT+ENTER

+ 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