+ Reply to Thread
Results 1 to 10 of 10

Sort Columns with multiple values in cells

  1. #1
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Sort Columns with multiple values in cells

    My columns are labeled A B C D etc... If the product I am creating the table for falls into one of those categories I place a 1 in the cell. For instance, ProductA falls into the A and B categories, so column A will get a 1 and column B will get a 1. This is so I can sort all of category A's Products etc...

    I am looking for a formula to put in a column that would Say what categories ProductA falls into. ie Since ProductA falls into the A and B catergories but not the C and D catergories, This final column would say something like AB, or A,B or something.

    Alternatively, I could make a single column entiltled 'categories' and put something like 'A B' in ProductA's column. In this case I would need a way to sort all A's or sort all B's and not just sort all 'A B'

    Any help would be greatly appreciated
    Last edited by CrystalNewb; 10-24-2009 at 01:02 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sort Columns with multiple values in cells

    Might be an idea to post a sample workbook.

  3. #3
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Sort Columns with multiple values in cells

    Here is a sample of what I am looking to do.
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sort Columns with multiple values in cells

    You can create the category list in F using something along the lines of

    =TRIM(REPT(B$1,B2)&" "&REPT(C$1,C2)&" "&REPT(D$1,D2)&" "&REPT(E$1,E2))

    In terms of "sorting"... ignoring the above, you can apply a Basic Auto Filter to row 1 and then filter by Column as desired
    (note however that with Auto Filter the filters are essentially "AND-esque" ... ie C = 1 AND D = 1 ... you can't have C = 1 OR D = 1 for that you'd need a column like the above (ie contains C or D))
    Last edited by DonkeyOte; 10-23-2009 at 03:17 PM.

  5. #5
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Sort Columns with multiple values in cells

    The formula worked great! Fogive me for being a bit ignorant when it comes to Excel, But could you explain a little bit of what the formula is doing? I evaluated the formula and still don't quite get what the TRIM and REPT functions do.

    Thanks again for your help.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sort Columns with multiple values in cells

    Quote Originally Posted by XL Help Files

    REPT Function

    Repeats text a given number of times. Use REPT to fill a cell with a number of instances of a text string.

    Syntax

    REPT(text,number_times)

    Text is the text you want to repeat.
    Number_times is a positive number specifying the number of times to repeat text.

    TRIM Function

    Removes all spaces from text except for single spaces between words.

    TRIM(text)

    Text is the text from which you want spaces removed.
    In the case of REPT the positive number is determined by the number in the appropriate cell (a blank will be seen as 0). The TRIM will remove the unnecessary spaces resulting from the concatenation.

  7. #7
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Sort Columns with multiple values in cells

    Thanks, that cleared a lot up.

    I'd like to take it a step further though.

    I have 2 colums A and B, in each of those columns I have 2 sub-columns, so to speak, A1, A2 and B1, B2. I want to say A if either A1 or A2 has a 1 in it and I want it to say B if either B1 or B2 has a 1 in it and I want it to say A B if any of the columns have a 1 in it.

    I've tried =CONCATENATE(TRIM(REPT(A$1,IF(OR(A1=1,B1=1),1,0)&" "&REPT(C$1IF(OR(C1=1,D1=1),1,0)))

    But if i have any 1's in my B column i get a #VALUE error.
    Thanks so much for your help so far.

    I've included an example
    Attached Files Attached Files

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sort Columns with multiple values in cells

    Based on your file

    F3: =TRIM(REPT(A$1,SUM(A3:B3)>0)&" "&REPT(C$1,SUM(C3:D3)>0))
    copied down

    in the above case we're using the boolean output of SUM(cells)>0 as the "positive number" in the TRIM...
    this we can do because Boolean TRUE will be equated to 1 and FALSE to 0 in the TRIM function

  9. #9
    Registered User
    Join Date
    10-23-2009
    Location
    Sarasota, Florida
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Sort Columns with multiple values in cells

    THANK YOU!!!
    Thanks for your help! Everything worked GREAT!

    My only other question regarding this thread would be how to mark it as solved...

    Thanks again

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sort Columns with multiple values in cells

    To quote the standard reply

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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