+ Reply to Thread
Results 1 to 23 of 23

Sort array depending on 2nd column

  1. #1
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Sort array depending on 2nd column

    Hi!

    I would like to sort one array (1 column) based on another column.

    Column 1 is the column to be sorted but I only want to sort if column B is blank ("").

    I can't get my formula to work.

    Please check the attached workbook.

    Thank you for your help!
    Attached Files Attached Files
    Last edited by pmguerra; 04-15-2010 at 06:10 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    Try:

    Please Login or Register  to view this content.

    confirmed with CTRL+SHIFT+ENTER
    not just ENTER and copied down as far as you want to retrieve all data.
    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.

  3. #3
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    Thank you for your help, NBVC!

    However the array is not sorted, it just eliminates the blank cells. For example, the values of rows 47 and 48 should be the first ones to appear.

    That's why I used INDEX, MATCH, SMALL and so on, trying to follow other examples of sorting.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    Add a helper column in C2:
    Please Login or Register  to view this content.
    copied down

    Then in E2:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER and copy down.

  5. #5
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    ok! That did the trick...

    One more question... How to avoid blank cells from being sorted?

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    You mean the opposite of what I just did?

  7. #7
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column



    of course not! Let me explain

    In your first post you helped me with a formula that eliminated blanks but did not sort the array.

    In the second post you gave me a formula which sorted the array but does not eliminate blanks.

    What I asked you just now is how to get a SORTED array WITHOUT blanks.

    thank you again for your help!

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    I think that is what I gave you last....

    No??
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    Ok, I know what you mean. Yes I used you formula and it worked perfectly.

    However the original data isn't all neat and clean like this. I didn't explain this to you, my bad.

    Try erasing any value in column A and you'll understand what I'm saying.

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    Change C2 formula to:

    =IF(A2="","",COUNTIF($A$2:$A$100,"<"&A2))

    copied down.

  11. #11
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    hmmmm....

    It works but it returns #N/D for the first 9 cells of the array...

    I don't understand why...

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    Another revisiion required to meet your last needs...

    Formula in E2 changed slightly to:

    Please Login or Register  to view this content.
    confirmed with CSE and copied down

    or to reduce calcs... add =SUMPRODUCT(--($A$2:$A$100<>""),--($B$2:$B$100="")) to a blank cell, like D2, then formula in E2:

    Please Login or Register  to view this content.

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    Quote Originally Posted by pmguerra View Post
    hmmmm....

    It works but it returns #N/D for the first 9 cells of the array...

    I don't understand why...
    make sure your cell ranges match your data...

    Post a more indicative example showing the new problem.

    Also, see my last added post....

  14. #14
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    Definitely I can't get it to work...

    I'm sending the file attached. Can you take a look?

    Thank you for your help and patience...
    Attached Files Attached Files

  15. #15
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    You have somehow made C2 in the IF() logical test within the SMALL() function relative... it should be Absolute:

    Please Login or Register  to view this content.
    Also, it looks as though you have changed the requirement to show items where column C is not blank.. originally you said where C is blank.

    If that is the case, then change change F2 to: =COUNTA(C:C)-1
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    Yes, you are right, it should be blank.

    I've corrected it and also the relative reference.

    I now know why I get an #N/D error. If you change the ranges from 550 to 560 (filled with blank cells), you will also get 10 #N/D and then the correct values.

    But why doesn't this happen for the other cells which are also blank?

  17. #17
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    Not sure what you mean.. rows 550 to 560 are already blank.

    Also, if you are identifying the blank column C values, then revert back to the Sumproduct formula in F2 to identify number of entries.
    Last edited by NBVC; 04-14-2010 at 08:51 AM.

  18. #18
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    Definitely not getting it right...

    One more detail... When I add one row to the middle of the range, I get the #N/D error... Even in the example file you worked on...

    I'll have to try and figure out if there's something wrong witth the data and work from there.

    Thank you very much for you time, you've been a great help!

  19. #19
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    I just inserted a row (with details) into the last file I attached... and I get no errors. I only get a blank row in the results because of inserted row.. just copy formula down from above and all is okay.

    Can you post this situation?
    Last edited by NBVC; 04-14-2010 at 12:43 PM.

  20. #20
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    I'm retrieving the data from another wokbook.

    Can this be causing the problem?

  21. #21
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sort array depending on 2nd column

    It might... kind of depends on how you are retrieving the data, what is actually being returned (ie. real blanks or not, special chars, etc). Are some things manually entered and some automatically retrieved?

    Are you getting #N/A error or #NUM error in english... I am not sure what #N/D translates to.. And is it only showing up at bottom of list? If so, then there is a counting problem somewhere.. either in the formula in column D or the formula in F2.

    It would be easiest to see a most realistic sample of what you are working with.

  22. #22
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    Sorry about the english:

    #N/D translates to #N/A and it appears at the top of the sorted range.

    I'll prepare you a sample of this workbook and attach it.

    Thank you

  23. #23
    Forum Contributor
    Join Date
    10-04-2004
    MS-Off Ver
    2013
    Posts
    148

    Re: Sort array depending on 2nd column

    SOLVED!!!

    The problem was with the helper column which had a wrong range...

    Thank you very much for your help!

    I was getting desperate...

    MANY THANKS!!!

+ 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