a compare column macro

ace2356

New Member
Joined
May 17, 2017
Messages
10
I am trying to modify my macro

1) to have order not matter in the columns
2) show what is missing from either column
3) sort the results in lowest to highest

example
column 1 column 2
5 3
1 1
7 5
2 7


Sub Compare()
'
' Compare Macro
'
Dim i As Long, _
LRa As Long, _
LRb As Long, _
rowx As Long

LRa = Range("A" & Rows.Count).End(xlUp).Row
LRb = Range("B" & Rows.Count).End(xlUp).Row
rowx = 2
Application.ScreenUpdating = False
For i = 2 To LRa
If IsError(Application.Match(Range("A" & i).Value, Range("B2:B" & LRb), 0)) Then
Range("C" & rowx).Value = Range("A" & i).Value
rowx = rowx + 1
End If
Next i
For i = 2 To LRb
If IsError(Application.Match(Range("B" & i).Value, Range("A2:A" & LRa), 0)) Then
Range("C" & rowx).Value = Range("B" & i).Value
rowx = rowx + 1
End If
Next i


End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Ace,

Not sure what more you wanted to do with this macro since it already identified what was missing from each column and placed them in column C. I just added the sort portion to the end.

Code:
    With Sheets("Sheet1").Sort
        .SetRange Range("C2:C" & LRa)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

Let me know if this is what you needed.

Bill
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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