+ Reply to Thread
Results 1 to 2 of 2

Sort and match whole columns' data?

Hybrid View

coolieku Sort and match whole columns'... 07-09-2009, 12:17 AM
rylo Re: Sort and match whole... 07-09-2009, 12:52 AM
  1. #1
    Registered User
    Join Date
    07-09-2009
    Location
    hong kong
    MS-Off Ver
    Excel 2003
    Posts
    17

    Sort and match whole columns' data?

    Hi, everyone, i am an excel beginner, i now have an excel that contains 3 columns that column B and column C are matched already.(below)

    A B C
    1 4 4.1
    2 5 5.1
    3 6 6.1
    7 1 1.1
    2 2.1
    3 3.1

    how to change to that as follows? (below)
    A B C
    1 1 1.1
    2 2 2.1
    3 3 3.1
    NIL 4 4.1
    NIL 5 5.1
    NIL 6 6.1
    7 NIL NIL

    i want the smallest number should be at the top, and if A and B are not matched, Nil will be shown.
    Thanks everyone....better to provide me the steps and method/code.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Sort and match whole columns' data?

    Hi

    This works with your sample data, assuming it is in the range A1:C6.

    However, if your real data is likely to contain a number in column A that doesn't have a match in column B, then it will have to be revised.

    Sub aaa()
    'sort columns B and C based on column B
      Range("B:C").Sort order1:=xlAscending, key1:=Range("B1")
    'step through the data in column A, and if the number is > than the number
    'in column B, then shift it down.
      For i = 1 To Cells(Rows.Count, 2).End(xlUp).Row
        If Cells(i, 1) > Cells(i, 2) Then Cells(i, 1).Insert shift:=xlDown
      Next i
    End Sub
    rylo

+ 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