Re: How to find duplicate data in an array by Peter
Peter
Mon Feb 13 08:17:57 CST 2006
Something like the following, perhaps?
Sub debugprintdups()
Dim Schedule(100, 2) As String
Dim strResult() As String
Dim i As Long
Dim j As Long
' some sample data
Schedule(1, 1) = "name1"
Schedule(2, 1) = "name2"
Schedule(3, 1) = "name3"
Schedule(10, 1) = "name1"
Schedule(11, 1) = "name1"
Schedule(19, 1) = "name1"
Schedule(1, 2) = "info1"
Schedule(10, 2) = "info2"
Schedule(11, 2) = "info3"
Schedule(19, 2) = "info4"
Schedule(2, 2) = "info5"
Schedule(3, 2) = "info6"
' Create our array of results
ReDim strResult(LBound(Schedule, 1) To UBound(Schedule, 1))
For i = LBound(Schedule, 1) To UBound(Schedule, 1)
For j = LBound(Schedule, 1) To i - 1
If Schedule(j, 1) = Schedule(i, 1) Then Exit For
Next
If j = i Then
strResult(i) = Schedule(i, 1) & " " & Schedule(i, 2)
Else
strResult(j) = strResult(j) & " " & Schedule(i, 2)
End If
Next
For i = LBound(strResult, 1) To UBound(strResult, 1)
If strResult(i) <> "" Then
Debug.Print strResult(i)
End If
Next
End Sub
Peter Jamieson
"Charlie" <Charlie@discussions.microsoft.com> wrote in message
news:E5FF9202-D2AD-4523-A719-36863A00C91D@microsoft.com...
>I have a string arrary Schedule(Names, Info)
> There are about 100 names in the array, but some of them are duplicates.
> How can I debug.print each Name, then the info that goes with it, and if
> it
> has a duplicate Name in the array, the info from that part also. The
> array
> is not sort in any way
> thanks,
> ck