+ Reply to Thread
Results 1 to 9 of 9

one macro to sort text in ascending and descending order

  1. #1
    Forum Contributor
    Join Date
    06-03-2008
    MS-Off Ver
    Excel 2007 (also have access to Excel 2000/2003)
    Posts
    368

    one macro to sort text in ascending and descending order

    Hi,

    Is it possible to sort a range of data in ascending and descending order using just one macro? I can have two macros with the alternate choices on but I would really like just the one option.

    I can do it if there is numerical data using this code:

    Please Login or Register  to view this content.
    Any ideas?

    Thank you in advance.

    JP

  2. #2
    Registered User
    Join Date
    01-18-2005
    Location
    Australia
    Posts
    29
    Hi JP,

    Try this:

    Please Login or Register  to view this content.

  3. #3
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    try this recorded macro
    copies col a to b
    then sorts
    a ascending
    b descending
    Please Login or Register  to view this content.

  4. #4
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Are you looking for this kind of control?

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    06-03-2008
    MS-Off Ver
    Excel 2007 (also have access to Excel 2000/2003)
    Posts
    368
    Thank you guys for such a comprehensive list of replies. I really appreciate it.

    ShaunM your suggestion was closest to what I was looking for. However it worked the first time I clicked the macro but click it again i.e. to swap ascending for descending or vice versa it didn't work. Any ideas?

    mikerickson thankyou for your reply, pardon my pathetic knowledge but how do I assign an If statement VBA code to a macro button?

    Thanks again,

    JP

  6. #6
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Write a Macro.
    Get a button from the Forms menu.
    Right click on the button and select Assign Macro from the pop-up menu.

    Here's a test macro.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-18-2005
    Location
    Australia
    Posts
    29
    Hi JP

    I have retested the code and it appears to work for me, Each time I click the button it resorts.

    I am not sure why it wouldn't run a second, third, fourth ...... time

    Shaun
    Attached Files Attached Files
    Last edited by ShaunM; 07-02-2008 at 07:42 PM.

  8. #8
    Forum Contributor
    Join Date
    06-03-2008
    MS-Off Ver
    Excel 2007 (also have access to Excel 2000/2003)
    Posts
    368
    Thanks ShaunM,

    Your file works perfectly for numbers but I need the same functionality for text. Any ideas?

    Thanks

    JP

  9. #9
    Registered User
    Join Date
    01-18-2005
    Location
    Australia
    Posts
    29
    Hi JP

    The code that I previously provided, handles numbers or words(strings).

    I have attached the same code with a word list to sort:

    Regards
    Shaun
    Attached Files Attached Files

+ 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