+ Reply to Thread
Results 1 to 28 of 28

Compare 2 columns then give count

  1. #1
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24

    Compare 2 columns then give count

    I need a formula to look in column B and find all "jun" (or anything else that I put in there) THEN look in column J and find only all "d" (d is one of 3 choices there) that correspond to the "jun" then give me the count of the "d".


    This is an example. With the formula I can do a variety of things to get info that I'd like to have.

    Thanks,
    George4

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Sounds like you could use SUMPRODUCT, try like

    =SUMPRODUCT(--(B2:B100="Jun"),--(J2:J100="d"))

    Note: I'm assuming that column B contains text, if it contains dates then you might need to change to

    =SUMPRODUCT(--(MONTH(B2:B100)=6),--(J2:J100="d"))

  3. #3
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    daddylonglegs:

    Yes. The first one is working...I think.

    It works great on a practice page but when I use it on the real thing it's not seeing all of the d's that I can physically count.

    I haven't figured out why yet, but the equation (first one you gave me) should work when I get the problem solved.

    Thanks!

  4. #4
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    This is crazy! Out of 5 months I've done on the actual spreadsheet...none of them come out correctly. The totals vary between 1 and 5 in difference, but it works on the test page. ???

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Are all the values in column B all excel serial dates or are some text like "Jun"?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    Only text. First 3 letters of each month. Just used as an identifier as there could be 5 in one month and 25 in another month. With the identifier I pull out all of whatever month then find how many d's or l's (L's) {column J on my spreadsheet} then that number is sent to another sheet for different information. I just used "d" to explain the situation.

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582
    Try breaking out the formula to see where the problem lies.
    Please Login or Register  to view this content.
    should match your Jun count and
    Please Login or Register  to view this content.
    should match your d count. If it's your d count, look for blanks before or after your d's. Excel is looking for an exact match.

    If you can, highlight the column with the d's and search for blanks and replace with nothing.

    Any of this help?

    ChemistB

  8. #8
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    ChemistB,

    Sorry I haven't gotten back sooner. I'm just home off of the road for a couple of days (OTR truck driver) and have TONS of stuff to pack into the 2 days.

    I will try what you said and see if it works. I don't think that's it though. The columns are only big enough for the letters listed above and they are centered so they go in the same every time.

    It may help me find something though. We'll see.

    Thanks for the help.

  9. #9
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    ChemistB,

    I think I figured it out w/your help.

    For each week of the month there is one of many different headings listed as D/L/U. This is for the J Column in my example. If there is a "d" in that column directly beneath the D/L/U it picks it up as (not sure what you call it) predictive text(?) and when you hit the space key so it just inserts the d as opposed to letting the D/L/U stay, that d is like a fraction of a space off of center of the rest of the d's in the column.

    Not even sure how I fixed it now. I just kept juking with the backspace, d, and enter key till the d stayed in the proper position then it would be counted correctly.

    Any ideas how to keep that from happening? Hate to turn off the predictive text as it comes in very handy in other repeated entries on the spreadsheet.

  10. #10
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    I also meant to ask why in the formula you can't just put B:B to look in the entire column. I've done that before but it doesn't seem to work here.

  11. #11
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    My Bad! That was daddylonglegs that helped me with the problem.

  12. #12
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582
    If there is a "d" in that column directly beneath the D/L/U it picks it up as (not sure what you call it) predictive text(?) and when you hit the space key so it just inserts the d as opposed to letting the D/L/U stay
    When you hit the space key it enters a space after the d. Use the backspace key instead. That will leave the d without spaces.

    ChemistB

  13. #13
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    Using the same idea, (first looking at column B for the letters JUN)... how would I get it to see only numbers in a different column, say column T and then get a total and/or average for numbers that correspond with JUN?

    The T column would only have numbers or n/a in it.

    I have Excel 2003.
    Last edited by George4; 09-08-2008 at 03:21 AM. Reason: Add more info

  14. #14
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582
    Quote Originally Posted by George
    Using the same idea, (first looking at column B for the letters JUN)... how would I get it to see only numbers in a different column, say column T and then get a total and/or average for numbers that correspond with JUN?
    For Totals;
    Please Login or Register  to view this content.
    For Average;
    Please Login or Register  to view this content.
    Does that work?

    ChemistB

  15. #15
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    The Total worked, the Average says: "You've entered too many arguments for this function"

  16. #16
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    Any ideas on the average?

  17. #17
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582
    Sorry, I must have posted that before coffee (or after too much!) The formula should have been
    Please Login or Register  to view this content.
    How's that working?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  18. #18
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    Well....it is giving me a number now, but it isn't the average. This will give me something to work on and see if I can find where the problem is.

    Thanks, ChemistB

    George4

  19. #19
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    OK. It's working on a test page. I must be doing something wrong. Still working on it.

  20. #20
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    Here's the problem.

    It's counting the n/a's with the numbers. Is there a way for it to see only the numbers in the column and not "words"?

  21. #21
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582
    Yes,
    We can take out the COUNTIF and replace it with a SUMPRODUCT like so;
    Please Login or Register  to view this content.
    Does that work?

    ChemistB

  22. #22
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    Sweet! You rock! I think that's what you were going for before but lacked the last part.

    How does someone learn this stuff?

  23. #23
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582
    I learned all of this stuff from reading these boards and trying things out. My thanks to all the mods and gurus who have helped me out.

  24. #24
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24

    Compare 2 columns then give count

    I'm so sorry! I messed up.

    I compared the wrong cell on your answer and thought that your last answer was correct but it was the same as the previous formulas answer.

    The attachment should help. I should have done this at first probably.

    As a refresher to what I'm needing:
    First look at column B for the letters JAN. Then, see only numbers in column C and then get an average for numbers that correspond with JAN. It's still counting all criteria in column C and dividing by that number rather than just the numerical total.

    The attachment will make this a lot clearer.

    Thanks Again,
    George4
    Attached Files Attached Files

  25. #25
    Forum Contributor
    Join Date
    10-27-2006
    Location
    United Kingdom
    MS-Off Ver
    EXCEL 2003 (2007 at home)
    Posts
    517

    oops,

    Try using the ISNUMBER function as follows:

    =SUMIF(B2:B1000,"Jan",C2:C1000)/SUMPRODUCT(--(B2:B1000="Jan"),--ISNUMBER(C2:C1000))
    Last edited by Mark@Work; 09-20-2008 at 06:02 PM. Reason: Got mixed up

  26. #26
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24
    EUREKA!

    That works on everything I've tried it on so far....that must be it!

    Now I'm going to study it and see how it works and how I can use it for other statistics I'd like to track.

    Thanks to all who helped,
    and thank you Mark@Work

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

    re: Compare 2 columns then give count

    COUNTIF(B2:B10,"Jun") Counif takes two arguments (Range, Criteria)
    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

  28. #28
    Registered User
    Join Date
    08-26-2008
    Location
    Oklahoma
    Posts
    24

    I can not find this prefix dropdown of which you speak

    Hope this one was titled well enough as to not incur another infraction.

    If I could find the drop down I would mark this thread "solved".

+ 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. Compare Columns and Find Difference
    By waki01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2008, 02:05 PM
  2. Count Number of Columns
    By mrdata in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-03-2007, 04:44 PM
  3. formula to get the count based on criterial in two or more columns
    By sunilbm in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-03-2007, 01:13 PM
  4. Compare Columns
    By DekHog in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-04-2007, 07:33 PM
  5. Compare Two Columns In Two Worksheets To Copy And Paste A Third Column
    By uopint in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2007, 05:03 PM

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