+ Reply to Thread
Results 1 to 8 of 8

Dynamic sort a range of cells and its descriptions

  1. #1
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Dynamic sort a range of cells and its descriptions

    Hello,
    I have a table with two columns shown below. the tablet rows holds the names will be 99 rows (A2:A100).
    I need a VBA or function if I add a new name in B6 and description in C6, the dynamic sorted name list
    (sorted by alphabetically from A to Z) will be dynamically sorting including its description. I prefer a function
    or VBA without a command button if possible, otherwise I am OK with a "Sorting" command button.


    Thanks


    Col 1.......Col B...............Col C
    A1..........Name...............Description
    A2..........Amazon............On-Line shopping
    A3..........Yahoo...............Web site
    A4..........Stop&Shop.........Supermarket
    A5..........Macy's...............Department store
    Last edited by Rocky2013; 01-27-2017 at 12:50 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Dynamic sort a range of cells and its descriptions

    The only way to do it without buttons is to either make it sort when something changes, I assume you enter description last, so this code would only do something when a new description is entered. The code needs to be in the worksheet object, not in a normal module.

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Dynamic sort a range of cells and its descriptions

    Hello,
    Thanks for the reply. It works.

    Thanks

  4. #4
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Dynamic sort a range of cells and its descriptions

    Hello,
    I change your code to a range (A2:B20) instead entire columns. I am not sure if I did it right.

    I did some testing for fool proof, I found some issue (may not an issue)
    1. Add entry to row A20/B20, and above, the new add will be sorted dynamically. WORKING
    2. I delete new texts in test 1. Then I add entry to row A21/B21, it does not sort. WORKING
    3. I keep the the texts in A21/B21. Then I enter texts to A20/B20, then row text in A20:B21
    sorted and moved up including color fill in A21/B21.

    Note: The color fill on my final file is not presented. I use that for visual to indicate the row and
    any rows below should not be sorted.

    In my spread sheet, I may have other information that are not part of the sorting.

    I am looking for if there is away in the code to prevent the text in A21/B21 and
    beyond from dynamic sorting if a new entry is enter above A21/B21.
    Last edited by Rocky2013; 01-27-2017 at 11:50 AM.

  5. #5
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Dynamic sort a range of cells and its descriptions

    Hello,
    I change your code to a range (A2:B20) instead entire column. I am not sure if I did it right.
    I did some testing for fool proof, I found some issue (may not an issue)

    1. Add entry to row A20/B20, and above, the new add will be sorted dynamically. WORKING
    2. I delete new texts in test 1. Then I add entry to row A21/B21, it does not sort. WORKING
    3. I keep the the texts in A21/B21. Then I enter texts to A20/B20, then row text in A20:B21
    sorted and moved up including color fill in A21/B21.

    Note: The color fill on my final file is not presented. I use that for visual to indicate the row and
    any rows below should not be sorted.

    In my spread sheet, I may have other information that are not part of the sorting.

    I am looking for if there is away in the code to prevent the text at A21/B21 and
    beyond from dynamic sorting if a new entry is enter above A21/B21.

    Thanks

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Dynamic sort a range of cells and its descriptions

    "If Not Intersect(Target, Range("B2:B20")) Is Nothing Then" this is the area where a change should trigger sort.
    "lr = Range("B" & Rows.Count).End(xlUp).Row" this is used to sort later, it finds the last row with data in B, even if that is row 1500

    "Range("A1:B20" & lr).Sort key1:=Range("A1"), order1:=xlAscending, Header:=xlYes"
    Ok so this is no good.... you can't say Range("A1:B20" & lr) so maybe change that to:
    Please Login or Register  to view this content.
    Last edited by Arkadi; 01-27-2017 at 12:23 PM.

  7. #7
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Dynamic sort a range of cells and its descriptions

    Hello,
    Wow! You are good, It works! you make it very simple.

    Thanks

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Dynamic sort a range of cells and its descriptions

    My pleasure! glad I could help

+ 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] sort inside a dynamic range
    By peter_swe in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-29-2016, 10:49 AM
  2. How to alphabetically sort values in a dynamic range?
    By max3732 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-20-2014, 07:54 AM
  3. [SOLVED] How to dynamic copy a range of cells and sort them?
    By nchinas in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-03-2014, 03:33 PM
  4. [SOLVED] Sort dynamic range alphabetically - cant get it working
    By Taktiker in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-08-2013, 11:35 AM
  5. Sort Dynamic Variable Range
    By GetSet in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-24-2010, 08:42 AM
  6. Excel 2007 : Sort a dynamic range alphabetically
    By lmsexcelforum in forum Excel General
    Replies: 2
    Last Post: 01-26-2009, 11:42 AM
  7. dynamic range - sort
    By sach0025 in forum Excel General
    Replies: 2
    Last Post: 02-02-2007, 05:14 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