PDA

View Full Version : Question on Array



arrun
11-16-2012, 02:13 PM
Hello again, in my following VBA functions, I have 2 arrays 'Array1' and 'Array2':

Sub MySub()
Dim Array1(5), Array2(5) As String
Array1(1) = "a"
Array1(2) = "c"
Array1(3) = "d"
Array1(4) = "b"
Array1(5) = "e"

Array2(1) = "c"
Array2(2) = "a"
Array2(3) = "b"
Array2(4) = "e"
Array2(5) = "d"

End Sub

What I need to do is to see :
1. whether there is any repetition in any array (like if 'a' is coming more than once).
2. whether 2nd array has all the elements that array1 has?

can somebody help me with some pointer how to achieve those?

Thanks for your help.

mikerickson
11-16-2012, 08:35 PM
Try this UDF


Function HasDuplicate(someArray As Variant) As Boolean
Dim i As Long
For i = LBound(someArray) To UBound(someArray)
HasDuplicate = HasDuplicate Or (i <> Application.Match(someArray(i), someArray, 0)
Next i
End Function