Consulting

Results 1 to 13 of 13

Thread: Solved: Sorting Question

  1. #1

    Solved: Sorting Question

    Ok, I've got what I believe is a fairly basic question, but it's stumpin me.

    If I've got database of the following:

    Joe 2 7 9
    Sam 1 3 4
    Dan 3 5 8

    So, the first two columns of numbers are simply data i've entered. The third column is a sum of the first two (a2 + a3) .... (or 2 + 7 = 9).

    My question is this. is there a way for me to sort the third column (containing the formula) into ascending or descending? I'd like to eventually get this:

    Joe 9
    Dan 8
    Sam 4


    Any help is greatly appreciated. Thanks!

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Do you wish to do this with vba or just native excel function?
    to sort without vba just select all of the data and go to Data-Sort
    select colulmn C and decending...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I'm sorry...I guess that would be column D and decending
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    First, I'd prefer to do it in Excel, as I don't know any Visual Basic...but if there's a simple way, I'd be happy to give it a try.

    Second, the simple "sort ascending" and "sort descending" buttons don't work because the value in column d is the result of a formula. As soon as it sorts it, the reference fields are changed and the values change.

  5. #5
    I guess I could make the field references static ($a$2 + $a$3)...but there are two difficulties with this...

    1. I'd have to manually add the $ to every cell for a large database.

    2. I'd like to associate the name with the number. ie: when column d gets sorted, the name that's associated with the value in column d gets sorted as well (with respect to column d).

    thanks for any help you can provide.

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Sam,
    could you post a sanitized version of your workbook? You keep using A2 and A3 and I think you mean B1+C1 for columns....am I right in this assumption?

    Second, the simple "sort ascending" and "sort descending" buttons don't work because the value in column d is the result of a formula. As soon as it sorts it, the reference fields are changed and the values change.
    This should not be happening and can only be happening if you are not selecting all of the data that you wish to sort...if you only select part...then only that part is sorted and yes your formula's will get messed up.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    You're right, it's b1 + c1. My mistake. So I'd be sorting column d. Everything is flowing horizontally. If you still need me to post a copy, I can in an hour or so. I'm at work now, and have to get back.

    thanks.

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    select all of the data..not just the column you want to sort by...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You should select any data that might be to the right of column D also so that each row stays together.....thought I should add that clarification.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You're right, it's b1 + c1. My mistake. So I'd be sorting column d.
    Sam..this is where your making your mistake I think....you don't want to just sort column d....you want to select all of the data and sort by column d.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    If it's easier you can use Control+A to select the entire worksheet and then sort by column D decending.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    Alright! It worked. I knew it was something simple that I was missing. Thanks for the help, I've been frustrated by this for a while.

    Sidenote, glancing through the posts here I've seen alot of visual basic references. How hard is it to learn / apply to excel?

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    How hard is it to learn / apply to excel?
    It's VBA in Excel that is posted here...Visual Basic for Appications which is not really Visual Basic which can create stand alone executable programs.

    Mostly depends on your need and how much your willing to put into it I guess. Most of the little I know I learned from following posts that interest me here at the forum....VBA Espress does offer some training for a small fee.

    I attached to this post an example from your question that has 2 macros in it that were both created using the macro recorder....Tools-macro-record new macro.

    The macro's can be viewed by hitting Alt+F11 and look for module1 on the left in the project explorer..double click module1 to see the code.

    Just start the recorder and go through your operations and click on stop when you have fininshed. The code does some extra operations that can be shortened later but it will give you a start and you can post questions here.

    Be sure to mark your thread solved using the thread tools at the top of the page when you have your solution..you can still post followup questions after marking it solved.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •