PDA

View Full Version : Solved: How to discover repeat text names in Range array?



jiura
04-14-2008, 07:53 AM
Hello to all!
I use Excel 2003 and I have an array of text data. This array consist of 15-20 text items in one column. I want to know has this array repeated text names or not. If I use Visual Basic with cycle in witch take?s the first name and then compare it with another?s, then take?s the second e.t.c. it ?s very long. How can I do it faster? If I only want to know has this array repeated text names or not.

lucas
04-14-2008, 08:07 AM
Do you just want a yes or no as to whether there are duplicats or do you want your array to only reflect a unique list of what is in the column?

mdmackillop
04-14-2008, 11:19 AM
Option Explicit
Sub test()
Dim d As Object, Rng As Range, cel As Range
Set d = CreateObject("Scripting.Dictionary")
Set Rng = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
For Each cel In Rng
On Error Resume Next
d.Add cel.Text, cel.Text
Next
If d.Count <> Rng.Cells.Count Then MsgBox "Duplicates exist"
End Sub

jiura
04-16-2008, 11:18 AM
That's is perfect! Thank you very much!