VBA Dictionary - Compare two Columns and extract unique

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I have two list of transaction ID. Compare it and Extract Unique Values.

Column A , Old list of transaction ID
Column B , New list of transaction ID


Colum C is a expected output. how to extract using Unique values using dictionary or any other method. Thanks.

Below is Table with expected output. Thanks.

Book6
ABC
1Old Transaction IDNew Transaction IDUnique Data
2111731117311246
3111751117511239
4111831118311247
5111851118511260
6112151121511257
7112171121711257
8112251124611259
91123111239
1011247
1111185
1211260
1311257
1411183
1511257
1611259
1711231
Sheet1


Thanks
mg
 
Hi Fluff,

I have corrected items, getting correct output. But getting date issue
In Dates place month has come and vice versa. expected output GHI, Macro output is KLM. How to sort this issue.

VBA Code:
Sub Mallesh()
   Dim Cl As Range

   With CreateObject("scripting.dictionary")
      For Each Cl In Range("c2", Range("c" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Array(Format(Cl.Offset(, -1), "DD/MM/YYYY"), Cl.Value, Format(Cl.Offset(, 2), "dd/mm/yyyy"))
       
         '.Item(Cl.Value) = Cl.Offset(, -1).Resize(, 3)
      Next Cl
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If .Exists(Cl.Value) Then .Remove Cl.Value
      Next Cl
      Range("K2").Resize(.Count, 3).Value = Application.Index(.items, 0, 0)
   End With
End Sub




Book2
GHIJKLM
1Post DateNew Transaction IDTransaction DatePost DateNew Transaction IDTransaction Date
216/08/20201124611/08/202016/08/20201124608/11/2020
318/08/20201123910/08/202018/08/20201123908/10/2020
409/08/20201124709/08/202008/09/20201124708/09/2020
523/08/20201126013/08/202023/08/20201126013/08/2020
611/08/20201125711/08/202008/11/20201125708/11/2020
707/08/20201125909/08/202008/07/20201125908/09/2020
Sheet1
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Don't format the dates, just use
VBA Code:
Cl.Offset(, -1).Value2
 
Upvote 0
Hi Fluff,


Tried Cl.Offset(, -1).Value2, Amazing it worked.


But if I use Just value.. it don't give correct output. whats the difference between .value and .value2
Cl.Offset(, -1).Value


Thanks
mg
 
Upvote 0
If a cell is formatted as a date value will return a VBA date, whilst value2 will return the underlying number.
 
Upvote 0
Hi, Fluff,

Thanks again for your help, I really likes your approach of array and dictionary . ?


Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,408
Members
449,448
Latest member
Andrew Slatter

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