Compare 2 columns and line up matching entries.

zeeek

New Member
Joined
Feb 9, 2009
Messages
10
Hi,
I'm wondering if anybody can assist me in solving this.
I have 2 columns of numbers. I want to match Col B to Col A and have the matching entries aligned next to one another.
ColA is the "Mater List" and I want to arrange ColB so that ColB's entries align themselves next to ColA's matching entry.
Basically, I am wanting to align matching entries in 2 columns.
Example below.

ColA.............ColB
10................12
14................54
27................10
44................27
98................98

RESULT
ColA.............ColB
10................10
14................
27................27
44................
98................98
...................12
...................54
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

You may try this code:
Code:
Sub arrangeA_B()
Dim last_row As Integer
Dim my_range As Range
Dim rag, c As Range
Dim temp
    
    last_row = Range("B" & Rows.count).End(xlUp).Row
    For x = 1 To last_row
        Set c = Range("A:A").Find(Range("B" & x).Value, LookIn:=xlValues, lookat:=xlWhole)
        If Not c Is Nothing Then
            If c.Row <> x And Range("B" & x).Value <> "" Then
                If c.Offset(0, 1).Value = Range("B" & x).Value Then
                    R = MsgBox("Duplication " & Range("B" & x).Value, vbOKOnly)
                    Exit Sub
                End If
                    
                temp = c.Offset(0, 1).Value
                c.Offset(0, 1).Value = Range("B" & x).Value
                Range("B" & x).Value = temp
                x = x - 1
            End If
        Else
            Range("B" & Range("B" & Rows.count).End(xlUp).Row + 1).Value = Range("B" & x).Value
            Range("B" & x).ClearContents
        End If
    Next
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,106
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top