+ Reply to Thread
Results 1 to 6 of 6

Very Specific Sorting Issue Using COUNTIF

  1. #1
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Very Specific Sorting Issue Using COUNTIF

    Hey Group,

    I have a list of class names in a spreadsheet and in the column to the left of the names, I have:

    =IF(ISBLANK(P2),"",1+COUNTIF(RawCourseList,"<"&P2))

    The purpose of this COUNTIF formula is to assess the number of entries within a range that are "less than" the class name (i.e. if along a column you have "A", "B", & "C" and you applied this formula in the cell to the left of "C", you would get "3" - A and B are both "less than" C, so this gets you 2, then the formula adds 1 to get 3 . This is essentially alphabetizing the list by creating a column that shows where each class name would fall if the list was sorted)

    However, the issue comes when I have two "C"s in the column. If I had "A", "B", "C", "C", & "D" along a column and applied the formula, I would get "1", "2", "3", "3", "5", where "3" is repeated and I never get "4". I know there is a way to change it so that the second "3" becomes a "4" but I forget how. Can anyone help me with this?

    *Using Data>Sort would NOT solve my issue.

    Thanks!

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: Very Specific Sorting Issue Using COUNTIF

    hi ALTGator, would be good if u can upload a sample

  3. #3
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Very Specific Sorting Issue Using COUNTIF

    Here is a sample doc. I have explained everything in the file - please let me know if it doesn't make sense.
    Attached Files Attached Files

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Very Specific Sorting Issue Using COUNTIF

    i added to your formulas as follows....

    in G3...
    =1+COUNTIF($H$3:$H$7,"<"&H3)+IF(ISERROR(VLOOKUP(H3,H4:$H$8,1,FALSE)),0,0.1)
    this adds 0.1 to the value to aid in tie-breaks

    =VLOOKUP(SMALL($G$3:$G$8,ROW(L1)),$G$3:$H$8,2,FALSE)
    this looks up the smallest (and next smallest) values
    you could change that to...
    =IF(G3="","",VLOOKUP(SMALL($G$3:$G$8,COUNT($G$3:G3)),$G$3:$H$8,2,FALSE)), which would base the =small() on the number of "numbers" you have

    let me know if this works on your live data?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: Very Specific Sorting Issue Using COUNTIF

    FDibbins - thank you for the inspiration. I didn't end up using your exact suggestion, but I was so focused on adjusting the equation I had that I didn't think to add another one as a tie breaker. Here is the addition I made:

    IF(COUNTIF(RawCourseList,"="&P62)>1,COUNTIF($P$2:P62,"="&P62)-1,0)

    Sometimes I may have 2, 3, or 4 courses with the same name, but in different formats. This assigns each dup name a different, sequential number and then the original formula picks up where the second formula leaves off when you get to the next name thats different.

    Thanks again.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Very Specific Sorting Issue Using COUNTIF

    the main thing is...your question is solved...and the beauty of excel is that there are so many different ways of arriving at the same sollution, sometimes we just need a little nudge to look at it from a different angle

+ 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