+ Reply to Thread
Results 1 to 4 of 4

Sorting a column

  1. #1
    Registered User
    Join Date
    10-16-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    28

    Sorting a column

    I have two columns, and I want to sort Column B in ascending order with vba code, but when column B is sorted, the corresponding cells in Column A should also be sorted together.

    So for eg.
    ColumnA | ColumnB
    Apple | 5
    Pear | 2
    Banana | 3

    After sorting it should display
    ColumnA | ColumnB
    Pear | 2
    Banana | 3
    Apple | 5

    What I have is:
    Please Login or Register  to view this content.
    and it isn't working, its not even sorting column B.

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Sorting a column

    Hi
    Try the following code:

    Please Login or Register  to view this content.
    Hope this helps

  3. #3
    Registered User
    Join Date
    10-16-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Sorting a column

    Hi thanks for reply. I've tried it but it gives an error saying Application-defined or object-defined error

  4. #4
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Sorting a column

    Hi
    The code I posted is based upon sorting the sample data you quoted, with Column headers in A1 and B1. So it should sort the range A1 to B4 by the values in column B. What is the range of data you are trying the code on? If it's different to the above then you'll have to amend the sort range in the code. Perhaps you could post a sample file of what you are having trouble with.
    Last edited by DBY; 10-17-2011 at 09:32 AM. Reason: Amended B2 to B1

+ 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