+ Reply to Thread
Results 1 to 7 of 7

Counting instance in a column, COUNTIF not working for it

  1. #1
    Registered User
    Join Date
    12-19-2012
    Location
    Spokane, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Counting instance in a column, COUNTIF not working for it

    Ok so I am trying to streamline the Shirt ordering process at my work. I have made a table with Employee names as Column A, then Row 1 is shirt sizes from small to XXXL. The Cell values are going to be the colors people want. I want to total the number of each size/color combination. But someone may want more than one of the same color. For instance you would enter "BK, BK" if you wanted 2 black shirts of that size. This is where the issue with COUNTIF comes in. If a cell has the same value twice, it only counts it as one because counts the cells with an instance of a value, not the actual count of instances. Is there a way to make COUNTIF or a better function for this?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,010

    Re: Counting instance in a column, COUNTIF not working for it

    This is a very difficult problem to solve with formulas the way you are organizing your data (maybe not even feasible). The best way to enter this type of data is to have one row for each combination of name/size/color, with the quantity for the combination:

    Name Size Color Quantity
    Fred XL BK 2
    Fred XL BL 1
    Janet M RD 1

    Then use formulas or a pivot table to determine any needed results, like how many of each size/color to order.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Counting instance in a column, COUNTIF not working for it

    See my attached sheet and see if it is something like what you are trying to do. The formula that determines how many BLACK shirts (or any other color with a change of notation) is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note: It is an ARRAY formula, entered by pressing CTRL + SHIFT + ENTER, instead of just enter.

    - Moo
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-19-2012
    Location
    Spokane, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Counting instance in a column, COUNTIF not working for it

    Amazing, That worked perfect Moo! Would you mind telling me why it worked? I can't quite understand what it is doing.

    Edit: Think i figured it out. It is counting the characters in the range, minus the characters that aren't "BK", then divided by the length of "BK" to give me a total instance number. Now that is thinking outside the box!
    Last edited by Alexm963; 02-24-2014 at 09:52 PM.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,010

    Re: Counting instance in a column, COUNTIF not working for it

    Moo the Dog, bravo! Very clever solution and should work with the given data organization. I still recommend better data layouts, but I'll bet this meets the OP's immediate needs.

  6. #6
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Counting instance in a column, COUNTIF not working for it

    SUM(LEN($B$2:$F$7) <-- Totals up all characters in range
    LEN(SUBSTITUTE($B$2:$F$7,"BK","")) <-- Total of all characters after removing desired color code, in this case "BK"
    /LEN("BK") <--- divide by length of desired string, in this case 2

    So you are totaling up all characters in the range, then subtracting the total characters left after removing the desired color code.

    I hope that makes sense?

    - Moo

  7. #7
    Registered User
    Join Date
    12-19-2012
    Location
    Spokane, WA
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Counting instance in a column, COUNTIF not working for it

    Yep makes perfect sense. Also to JazzStringer, I agree this is not an ideal layout. However if I did the way you suggested this sheet would get very large, very quick. With about 200 employees and 28 Color/Size combos, needing a line for each color/size/employee would make manual data entry a nightmare. I have a programmable keypad and have set a button for each color so I can enter things in very quickly.Thanks for all the help and suggestions though.

+ 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. [SOLVED] Counting and Summing only one instance of a record
    By smls in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-10-2013, 02:54 PM
  2. Number Each Instance in Corresponding Column
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2013, 02:21 PM
  3. First Instance of a Value in a Column
    By Roccobarocco in forum Excel General
    Replies: 2
    Last Post: 07-11-2009, 07:26 AM
  4. Replies: 0
    Last Post: 03-08-2007, 12:04 AM
  5. Countif - Counting time in a Column
    By TRM in forum Excel General
    Replies: 2
    Last Post: 10-06-2005, 10:05 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