+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    12-15-2009
    Location
    in a box
    MS-Off Ver
    Excel 2007
    Posts
    2

    sort and match two columns help

    Hello everyone,

    I have recently been asked to sort and match two columns of numbers. There are numbers that show up multiple times in each column. What I need is to find out which ones don't line up, and then insert either a cell in the one column. Example:

    A B
    11 11
    22 22
    33 33
    33 33
    33
    ' ' 66

    My example above isn't the best as I was not able to place a space in front of the number '66'. But what I am hoping someone can help me with is anytime the two columns are equal then the compare goes to the next row. Anytime column 'A' has a greater value there is a cell inserted and then it goes to the next line to see if the two numbers match.

    I have also attached an example of what I was explaining above.
    If there are any questions please let me know. I also just wanted to say thank you in advance.
    Attached Files Attached Files

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: sort and match two columns help

    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-15-2009
    Location
    in a box
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: sort and match two columns help

    Thank you shg this is almost exactly what I needed. Problem is it only sorts the right column and if the left column has a greater number than the right column it will insert cells on the right side until it hits the end of the list on the left. Please let me know if you have any idea how to change this so it will compare both columns and then insert the cell on the side that needs to shift down. Thanks again... and thanks for the really quick response


    Looks like I might have it... this is what I came up with below:

    Sub lineUpalt()
    Dim i As Long, lRow As Long
    lRow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To lRow
    Select Case Cells(i, 1)
    Case Is < Cells(i, 2)
    Cells(i, 2).Insert shift:=xlDown
    Case Is > Cells(i, 2)
    Cells(i, 1).Insert shift:=xlDown
    Case Else
    'do nothing
    End Select
    Next
    End Sub
    Last edited by techzone; 12-16-2009 at 01:07 PM. Reason: Figured out a working Macro

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0