+ Reply to Thread
Results 1 to 8 of 8

How to alphabetically sort values in a dynamic range?

  1. #1
    Forum Contributor
    Join Date
    04-01-2010
    Location
    USA
    MS-Off Ver
    Office 2021
    Posts
    185

    How to alphabetically sort values in a dynamic range?

    I have 2 columns of data, the 1st has names and the second has numbers. I'd like to sort the data alphabetically then get rid of the duplicate name in the name column and move the numbers over a column.

    I tried recording a macro using the sort in excel and when I put in the range I had set it gave an error (subscript out of range on the 2nd line that starts with "ActiveWorkbook").

    I checked the variable "SortRng" and it does refer to the 2 columns and rows I want. Here is the relevant code and an example of the kind of data I'm working with.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: How to alphabetically sort values in a dynamic range?

    Please Login or Register  to view this content.
    changed after HaHoBe advise
    Last edited by patel45; 07-20-2014 at 02:36 PM.
    If solved remember to mark Thread as solved

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

    Re: How to alphabetically sort values in a dynamic range?

    Hi, max3732,

    if you have more than one item to be listed patel45īs code will fail as only one cell is copied over (wiull always copy Column B to Column C no matter what information is on that line).

    First suggestion is to combine the contents in Column B:
    Please Login or Register  to view this content.
    Second would be to add the cells to the right of the first line the item appears on:
    Please Login or Register  to view this content.
    In your code sample you mention SortRng which depends on SortSt which isnīt defined. You should make sure to include this information for us if you post a procedure which is causing trouble.

    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

  4. #4
    Forum Contributor
    Join Date
    08-11-2012
    Location
    bengalur
    MS-Off Ver
    Excel 2003, 2007
    Posts
    152

    Re: How to alphabetically sort values in a dynamic range?

    HTML Code: 

  5. #5
    Forum Contributor
    Join Date
    08-11-2012
    Location
    bengalur
    MS-Off Ver
    Excel 2003, 2007
    Posts
    152

    Re: How to alphabetically sort values in a dynamic range?

    HTML Code: 

  6. #6
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: How to alphabetically sort values in a dynamic range?

    Hi..

    Here's another..

    Please Login or Register  to view this content.
    Attached Files Attached Files

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

    Re: How to alphabetically sort values in a dynamic range?

    Hi, shyamhappy,

    whatīs the use to post the code of another user twice into this post without any additional information? And why use HTML-tags instead of code-tags?

    @apo:
    you would need to dim
    Please Login or Register  to view this content.
    for making the code work in an Option Explicit environment.

    Ciao,
    Holger

  8. #8
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: How to alphabetically sort values in a dynamic range?

    @HaHoBe..

    You got me on that one.. I went back and 'thought' i had Dimensioned them all before posting..

+ 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. Formula to Index, Match, Rank, and Sort a Dynamic Range of Values
    By AustinLe in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-14-2014, 03:49 AM
  2. VBA code to sort range alphabetically once run an advanced filter
    By chrisjames25 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2014, 07:33 PM
  3. [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
  4. [SOLVED] Sort all sheets alphabetically, values separated by underscore
    By sans in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2012, 03:09 PM
  5. Excel 2007 : Sort a dynamic range alphabetically
    By lmsexcelforum in forum Excel General
    Replies: 2
    Last Post: 01-26-2009, 11:42 AM

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