XLA routines: EE_ArrayCommonElements
EE_ArrayCommonElements returns the common elements in 2 arrays
Function EE_ArrayCommonElements(array1 As Variant, _ array2 As Variant) As Variant Dim tempArray As Variant Dim i As Long 'http://excelexperts.com/xla-routines-eeArrayCommonElements for updates on this function ' start with a single element ReDim tempArray(0) ' if element in first array exists in second array, keep it For i = LBound(array1) To UBound(array1) If EE_IsInArray(array2, CStr(array1(i))) Then ' found! 'if filter(array2,CStr(array1(i))) ReDim Preserve tempArray(UBound(tempArray) + 1) tempArray(UBound(tempArray)) = array1(i) End If Next i ' first element is Empty, so shift all elements one position up For i = LBound(tempArray) To UBound(tempArray) - 1 tempArray(i) = tempArray(i + 1) Next i ' remove last element If UBound(tempArray) <> 0 Then ReDim Preserve tempArray(LBound(tempArray) To UBound(tempArray) - 1) End If EE_ArrayCommonElements = tempArray End Function
»
- Nick's blog
- Login or register to post comments
- 2809 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago