ruifazenda

New Member
Joined
May 29, 2019
Messages
1
I've a worksheet with data in 2 columns and i need compare then and extract the diferences to another columns.
There is a problem because i've repetitions in both columns and my macro doesn't work properly with this.
I think i need a new macro to do this.

Data1Data2
100100
100200
100200
200300
300500
400600
600600
700800
900

<tbody>
</tbody>

Results:

Faults:Data1Data2
500400
800700
900

<tbody>
</tbody>
This is wrong
REAL Faults are:
Data1Data2
200100
500100
600400
800700
900

<tbody>
</tbody>

Macro:

Sub abc()
Dim i As Long, ii
Dim arrBank, arrAccounting, arrOutput

arrBank = Range("a2:a" & Cells(Rows.Count, "a").End(xlUp).Row)
arrAccounting = Range("b2:b" & Cells(Rows.Count, "b").End(xlUp).Row)


With CreateObject("scripting.dictionary")
.CompareMode = 1
For i = 1 To UBound(arrBank)
.Item(arrBank(i, 1)) = Array(arrBank(i, 1), arrBank(i, 1))
Next

ReDim arrOutput(1 To UBound(arrAccounting), 1 To 1)
For i = 1 To UBound(arrAccounting)
If Not .exists(arrAccounting(i, 1)) Then
ii = ii + 1
arrOutput(ii, 1) = arrAccounting(i, 1)

End If
Next
.RemoveAll
Range("e2").Resize(UBound(arrOutput), 1) = arrOutput
For i = 1 To UBound(arrAccounting)
.Item(arrAccounting(i, 1)) = Array(arrAccounting(i, 1))
Next

ii = 0
ReDim arrOutput(1 To UBound(arrBank), 1 To 1)
For i = 1 To UBound(arrBank)
If Not .exists(arrBank(i, 1)) Then
ii = ii + 1
arrOutput(ii, 1) = arrBank(i, 1)

End If
Next
.RemoveAll
Range("f2").Resize(UBound(arrOutput), 1) = arrOutput
End With
Erase arrBank
Erase arrAccounting
Erase arrOutput
End Sub


Can anyone help me?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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