Compare the values of 2 columns and copy their defferences

acklovo2

New Member
Joined
Aug 1, 2012
Messages
3
hello!

I've been trying to resolve this but I can't finish it!

I have two workbooks, "Guides.xls" (workbook 1) and "Provider Guides.xls" (workbook 2). They have a lot of information but I only care the column with the numbers of guides and they can be in any column in the workbooks.

Is assumed that the numbers of guides are the same but we really don't know... So what I have to do is a macro that compare those columns and if there are more guides in any workbook, put them in another workbook.

I was working with this code but is not exactly what I need


Sub test()
Dim a, i As Long, b(), n As Long, x
a = Range("a1").CurrentRegion.Resize(,2).Value
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a,1)
If (Not IsEmpty(a(i,1))) * (Not .exists(a(i,1))) Then .add a(i,1), Nothing
Next
ReDim b(1 To UBound(a,1), 1 To 1)
For i = 1 To UBound(a,1)
If Not IsEmpty(a(i,2)) Then
If Not .exists(a(i,2)) Then
n = n + 1 : b(n,1) = a(i,2)
Else
.remove a(i,2)
End If
End If
Next
x = .keys
End With

With Range("d1")
.CurrentRegion.ClearContents
.Resize(,2).Value = [{"Not in A", "No in B"}]
With .Offset(1)
If n > 0 Then .Resize(n).Value = b
End With
On Error Resume Next
.Offset(1,1).Resize(.Count).Value = Application.Transpose(x)
End With
End Sub

I would be really gateful for your help. :)
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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