+ Reply to Thread
Results 1 to 11 of 11

Trouble with sorting

  1. #1
    Registered User
    Join Date
    10-14-2015
    Location
    Miami
    MS-Off Ver
    2010
    Posts
    20

    Trouble with sorting

    I can't beleive I can't make this work...

    All I am trying to do is sort a section of data on another tab in my spreadsheet and it does not work. Here is the code:

    Please Login or Register  to view this content.
    Please tell me what I am doing wrong.

  2. #2
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Trouble with sorting

    Hi
    You need a range of cells to sort for the sort key
    Key1:=Sheet9.Range(AV61") should be a range of cells like Key1:=Sheet9.Range("AV61:AV67") something like that

  3. #3
    Registered User
    Join Date
    10-14-2015
    Location
    Miami
    MS-Off Ver
    2010
    Posts
    20

    Re: Trouble with sorting

    It still returns an error I'm afraid:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Trouble with sorting

    Why don't you just record a macro.
    Start the macro recorder, and select the range and sort it as you want then stop the recording, look at the vba code and see what's wrong if you cross-check it with your macro
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  5. #5
    Registered User
    Join Date
    10-14-2015
    Location
    Miami
    MS-Off Ver
    2010
    Posts
    20

    Re: Trouble with sorting

    I did mate. That's how I got the original macro. I don't know why it does not work when I use it in another macro.

    I did have to change it from using the active sheet to referencing another sheet without selecting though. I guess that is what broke it.

    I also changed the sheet names to sheet codes...

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Trouble with sorting

    Hi mate,
    I used your macro, no changes except for the columns and it works with extra editing even if I call it from another sheet and from a macro

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Trouble with sorting

    I've learnt something out of this too. I didn't think of trying to do a sort with one cell as the key

    This is how i would do it
    Please Login or Register  to view this content.
    Good luck

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Trouble with sorting

    Hello rsmithline,

    The code you have would work with Windows prior to 2007 just fine. In 2007, sorting was expanded to apply to more objects.

    The old sort method only allowed for 3 levels of sorting. Now, it can handle as many levels as memory will allow. This is accomplished through the SortFields object.

    Each worksheet has its own Sort object. Anytime you do a sort, any SortFields that have been set previously will remain in effect. You should always clear the SortFields before add the fields you want to use.

    Here is an example using your code. The sort assumes there are headers in cells "AV61, AW61, AX61, and AZ61".
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: Trouble with sorting

    True, and you can add extra sorting conditions

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-14-2015
    Location
    Miami
    MS-Off Ver
    2010
    Posts
    20

    Re: Trouble with sorting

    Fixed now! Thanks guys!

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Trouble with sorting

    Hello rsmithline,

    You're welcome. Hopefully, the new sorting method makes more sense now.

+ 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] Formula Trouble When Sorting
    By ntate in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-06-2014, 07:44 PM
  2. Trouble with sorting dates
    By txfireman in forum Excel General
    Replies: 14
    Last Post: 04-19-2014, 09:30 AM
  3. Trouble with sorting
    By petevang in forum Excel General
    Replies: 3
    Last Post: 11-23-2012, 11:13 AM
  4. still trouble with sorting
    By speedstr in forum Excel Programming / VBA / Macros
    Replies: 43
    Last Post: 05-24-2012, 05:12 PM
  5. Excel 2007 : Trouble Sorting
    By rev-o-lution in forum Excel General
    Replies: 3
    Last Post: 11-06-2010, 12:00 PM
  6. Trouble Sorting Data
    By gonzo5000 in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 08-28-2007, 04:57 AM
  7. Trouble sorting a table???
    By FISH in forum Excel General
    Replies: 2
    Last Post: 09-27-2005, 05: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