+ Reply to Thread
Results 1 to 16 of 16

Sort Alphabetically

  1. #1
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Sort Alphabetically

    I am having difficulties with sorting my ranges alphabetically. Please see the attached file to see the structure of the data. I have a user form that inserts new rows at the bottom of each month and I need to sort column "A" each time a new record is inserted.

    Many thanks!
    Attached Files Attached Files
    Last edited by Bob@Sun; 01-13-2010 at 03:40 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Sort Aphabeticaly

    I would think this could work, it uses AutoFilter, selects the Non-Blank cells then sorts
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Sort Aphabeticaly

    This code does not sort the right way.

    I need each range to be sorted separated: A2:D8; A10:D16 ets.

    The code below is part of a user form and adds new row with the value of textbox. I need line that will sort ranges after the new row is inseted.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-27-2009
    Location
    Paris, France
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: Sort Aphabeticaly

    Hello,

    When your code insert a new row the Event Worksheet_Change call the macro SortRanges.

    1) Copy this code in standard module

    Please Login or Register  to view this content.
    2) Copy this code in the particular Sheet code window

    Please Login or Register  to view this content.

    Best regards.

    PMO
    Patrick Morange

    PS : Please, tell me if my language is correct.
    Attached Files Attached Files

  5. #5
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Sort Aphabeticaly

    Well this code gives me an error '1004' This Operation requires the merged cells to be identically sized,

    I do not have any merged cells but have cells with different size. If that is the reason for the error, I need another approach to the problem as i cannot make all rows with the same size.

    Besides that, I need this code to run only when I use the user form to insert new row.
    As am running another macros on the sheets where my using Worksheet_Change event is not good idea as it runs each time I am doing something else.

    I will appreciate some other ideas!

    Thanks!

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Sort Aphabeticaly

    Quote Originally Posted by Bob@Sun View Post
    Well this code gives me an error '1004' This Operation requires the merged cells to be identically sized,

    .........!
    You example did not have merged cells, merged cells are very hard to work with and it would be best if you got rid of them.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Sort Aphabeticaly

    Well this code gives me an error '1004' This Operation requires the merged cells to be identically sized,

    I do not have any merged cells but have cells with different size.
    If you think you don't have any merged cells, then select all the cells on the sheet and do Format > Cells > Alignment, untick Merge cells and try again.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Sort Aphabeticaly

    Actually the merged cells are not the problem in this case.

    As I explained, the approach in the code above does not suit my needs.
    I need a code that does not use the Worksheet_Change event because am i running different macros on the same sheet where my data is. That is why I need I code which will Sort the data only when I new rows are added to the range.

    I hope I explained well.

  9. #9
    Registered User
    Join Date
    12-27-2009
    Location
    Paris, France
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: Sort Aphabeticaly

    Hello,

    If your problem with merged cells arranged, here a new version with the code run when you use your UserForm

    1) Copy this code in standard module

    Please Login or Register  to view this content.
    2) Create an UserForm1 with a CommandButton1 and copy this code

    Please Login or Register  to view this content.
    With regards.

    PMO
    Patrick Morange
    Attached Files Attached Files

  10. #10
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Sort Aphabeticaly

    We are almost there!

    This code works ok, but needs a little change. When names in Column A are rearanged I need the information and the formating of the cells in the range B:AF to be aranged properly.

    I am attaching a sample file. Many thanks for the help!
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    12-27-2009
    Location
    Paris, France
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: Sort Aphabeticaly

    Hello,

    A new version with the following code

    Please Login or Register  to view this content.
    WARNING !
    To particularize the cells do not use diagonal borders for the cell format does not follow the sort. Instead, use a background color.


    Best regards.

    PMO
    Patrick Morange
    Attached Files Attached Files

  12. #12
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Sort Alphabetically

    Ok, in this case can you help me to change the code and use background color instead of diagonal borders.

    That is my old code

    Please Login or Register  to view this content.
    I tried to change it to

    Please Login or Register  to view this content.
    but it does not work properly.

  13. #13
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Sort Alphabetically

    I figured it out:

    Please Login or Register  to view this content.
    I will try now your code to sort the range and will see if everything is ok.

  14. #14
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Re: Sort Alphabetically

    Hi Patrick,

    Your code works perfect!

    Thanks for your help!

  15. #15
    Registered User
    Join Date
    08-23-2015
    Location
    cambodia
    MS-Off Ver
    2013
    Posts
    5

    Re: Sort Alphabetically

    hi Bob@Sun , Please help me
    i want to sort column A2:A , B2:B and C2:C...xx:xx
    thanks

  16. #16
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Sort Alphabetically

    Hi, sunblue,

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ 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