+ Reply to Thread
Results 1 to 14 of 14

Help with using Countif() across multiple columns

  1. #1
    Registered User
    Join Date
    01-15-2014
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    12

    Help with using Countif() across multiple columns

    I am trying to find a cleaner way to get a count of several cells in different columns in which the value is greater than zero.
    In the workbook I've attached at the bottom of the worksheet is "Avg Carb" and in the Count section I've used a bunch of Countif() to achieve the result, I am trying to see if there is cleaner code or an easier function that I could use to get the same results.
    For further explanation, the cells that the Countif() is calling to is a sum of all the numbers for each "carb" column.
    Let me know if there are any questions about what I am trying to do.
    I appreciate any help with this.
    Thanks
    Bob
    Attached Files Attached Files

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Help with using Countif() across multiple columns

    Try this......

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Contributor
    Join Date
    03-17-2005
    Location
    Canterbury, Kent
    MS-Off Ver
    2003, 2010
    Posts
    285

    Re: Help with using Countif() across multiple columns

    Did a search and found this...

    =SUM(COUNTIF( INDIRECT({"C13","E13","G13","I13","K13","M13","O13","C27","E27","G27","I27","K27","M27","O27","C41","E41","G41","I41","K41","M41","O41","C55","E55","G55","I55","K55","M55","O55"}), ">0"))

    Bit tidier.

    Windy

  4. #4
    Registered User
    Join Date
    01-15-2014
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Help with using Countif() across multiple columns

    Quote Originally Posted by sktneer View Post
    Try this......

    Please Login or Register  to view this content.
    Worked great for that group but nothing changes when I put something in cell C18 or anywhere else outside of the range B3:0O3
    Tried this code found by windy58:
    =SUM(COUNTIF( INDIRECT({"C13","E13","G13","I13","K13","M13","O13","C27","E27","G27","I27","K27","M27","O27","C41","E41","G41","I41","K41","M41","O41","C55","E55","G55","I55","K55","M55","O55"}), ">0"))
    and it worked, anyway to shorten this?
    Last edited by rcarruth; 05-25-2014 at 05:49 PM.

  5. #5
    Registered User
    Join Date
    01-15-2014
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Help with using Countif() across multiple columns

    Quote Originally Posted by windy58 View Post
    Did a search and found this...

    =SUM(COUNTIF( INDIRECT({"C13","E13","G13","I13","K13","M13","O13","C27","E27","G27","I27","K27","M27","O27","C41","E41","G41","I41","K41","M41","O41","C55","E55","G55","I55","K55","M55","O55"}), ">0"))

    Bit tidier.

    Windy
    That worked!!

  6. #6
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Re: Help with using Countif() across multiple columns

    More simpler approach :

    In the Avg Carb table, try,
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Saarang84; 05-25-2014 at 10:10 PM.
    If my assistance has helped, there is a reputation icon * on the left hand corner below the post - you can show your appreciation to the user who has helped in resolving your requirement.

    If your requirement has been solved please mark your thread as Solved.
    In the menu bar above the very first post, select Thread Tools, then select "Mark this thread as Solved".

    Kindly use [FORMULA] or [CODE] tags when posting your code.

    Regards,
    Sarang

  7. #7
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211

    Re: Help with using Countif() across multiple columns

    Quote Originally Posted by rcarruth View Post
    That worked!!
    ......but it's not an elegant solution

    Try this:

    =SUM(COUNTIFS(B3:O3,"Carbs",INDIRECT({"B27:O27","B13:O13","B41:O41","B55:O55"}),">0"))

  8. #8
    Registered User
    Join Date
    01-15-2014
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Help with using Countif() across multiple columns

    Quote Originally Posted by Teethless mama View Post
    ......but it's not an elegant solution

    Try this:

    =SUM(COUNTIFS(B3:O3,"Carbs",INDIRECT({"B27:O27","B13:O13","B41:O41","B55:O55"}),">0"))
    I'm actually using this code which seems to be working so far:
    =COUNTIFS(B13:O55,">0",B3:O45,"Carbs")

    I am using this spreadsheet in Google Docs and I'm finding that some of the functions which are working perfectly on a desktop Excel sheet do not work the same on Google Docs, very frustrating.
    Thanks for your help though.
    Bob

  9. #9
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211

    Re: Help with using Countif() across multiple columns

    Quote Originally Posted by rcarruth View Post
    I'm actually using this code which seems to be working so far:
    =COUNTIFS(B13:O55,">0",B3:O45,"Carbs")

    I am using this spreadsheet in Google Docs and I'm finding that some of the functions which are working perfectly on a desktop Excel sheet do not work the same on Google Docs, very frustrating.
    Thanks for your help though.
    Bob
    Excel <> Google Docs

    I know not thing about google doc.

    Google Docs may work on some basic formula, but I don't think it will work with complex formula.

  10. #10
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Help with using Countif() across multiple columns

    You may try this to see if this works on google spreadsheet

    Please Login or Register  to view this content.
    On Excel, the formula will be as follows.....

    Please Login or Register  to view this content.
    Last edited by sktneer; 05-26-2014 at 12:39 AM.

  11. #11
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,844

    Re: Help with using Countif() across multiple columns

    Here is my take on it. I added a helper column (A) to indicate the data rows to be summed and averaged, makes the formulas more compact.
    These are array formulas, they have to be entered with Ctrl + Shift + Enter.
    Attached Files Attached Files
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Help with using Countif() across multiple columns

    Quote Originally Posted by Teethless mama View Post
    ......but it's not an elegant solution

    Try this:

    =SUM(COUNTIFS(B3:O3,"Carbs",INDIRECT({"B27:O27","B13:O13","B41:O41","B55:O55"}),">0"))
    ......but it's not a robust solution

    Try this:

    =SUMPRODUCT((B3:O3="carbs")*(MOD(ROW(B13:O55)-ROW(B13),14)=0)*ISNUMBER(B13:O55)*(B13:O55>0))
    Last edited by Tony Valko; 05-26-2014 at 10:22 AM.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  13. #13
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Help with using Countif() across multiple columns

    Quote Originally Posted by Tony Valko View Post
    ......but it's not a robust solution

    Try this:

    =SUMPRODUCT((B3:O3="carbs")*(MOD(ROW(B13:O55)-ROW(B13),14)=0)*ISNUMBER(B13:O55)*(B13:O55>0))
    Why not "robust"?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  14. #14
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Help with using Countif() across multiple columns

    =SUM(COUNTIFS(B3:O3,"Carbs",INDIRECT({"B27:O27","B13:O13","B41:O41","B55:O55"}),">0"))
    If you happen to insert new rows/columns before the referenced ranges the formula "breaks".

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Countif using criteria in multiple columns
    By vesterholt in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-10-2014, 03:20 PM
  2. Countif multiple columns
    By benjaminswill in forum Excel General
    Replies: 4
    Last Post: 02-28-2012, 12:47 PM
  3. COUNTIF for multiple columns
    By jmenefee in forum Excel General
    Replies: 5
    Last Post: 03-19-2009, 07:38 PM
  4. using a countif with multiple columns
    By [email protected] in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-21-2006, 11:20 PM
  5. [SOLVED] Using Countif on multiple columns
    By ingeman in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-17-2006, 01:15 AM

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