Hi Mirabeau,
Thanks a lot for your script, it seems to be able to do what I need. I've tried running it but ran into a 'Run-time error 429, ActiveX component can't create object' on the line "Set d1 = CreateObject("scripting.dictionary"). Any idea of how I can fix this?
Also, will this find the unique values in each column? For example, if I have two columns RANGE1 and RANGE2, and RANGE1 contains 1, 1, 4 and RANGE2 contains 1, 2, 3 then the script should return that the unique value in RANGE1 is 1, and the unique values in RANGE2 are 2, 3.
Thanks again!
Hmm...
That's an unexpected hitch.
Here's some suggestions.
Can you create any other ActiveX objects with your hardware/software setup?
Is your syntax correct? That is, are you using the syntax exactly as I posted it?
Are you using a Mac?
What verion of Windows (if you're using Windows) and what version of Excel?
(I shouldn't really ask this, but just for completeness, were you using a legal copy of Excel?)
You can check the Microsoft website/knowledge base for more info on problems with creating activeX objects. Also usefully check Google on the topic.
You can use other methods of sorting out uniques, such as advanced filter, or alternative VBA codes.
If the data you need to check are just numbers, rather than text, then an easy and very fast workaround could be used.
Finally, you can try the following alternative code formulation and see if it does anything for you.
But follow these instructions before trying to run it.
1. Open the code module window. Say by pressing Alt+F11
2. At the menu on the top, click tools, then references
3. Scroll down to Microsoft Scripting Runtime, and check (or tick) that
4. Run the following code
Code:
Sub compare_A_and_E()
Dim d1 As New dictionary, d2 As New dictionary
Dim lra As Long, lre As Long
Dim u(), v()
Dim ka As Long, ke As Long, c
d1.CompareMode = 1
d2.CompareMode = 1
lra = Range("A" & Rows.Count).End(3).Row - 1
lre = Range("E" & Rows.Count).End(3).Row - 1
ReDim u(1 To lra, 1 To 1), v(1 To lre, 1 To 1)
For Each c In Range("A2").Resize(lra).Value
d1(c) = 1
Next
Range("B2").Resize(d1.Count) = Application.Transpose(d1.Keys)
Range("B1") = "Unique in A"
For Each c In Range("E2").Resize(lre).Value
d1(c) = 1
d2(c) = 1
Next
Range("F2").Resize(d2.Count) = Application.Transpose(d2.Keys)
Range("F1") = "Unique in B"
Range("H2").Resize(d1.Count) = Application.Transpose(d1.Keys)
Range("H1") = "Unique over both"
End Sub