View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rowan[_2_] Rowan[_2_] is offline
external usenet poster
 
Posts: 226
Default How to exclude a list of number from another list?

This worked for me

'Assumes array1 and array2 are allready
'dimensioned and populated
'NewArray will hold the list of unique
'numbers

Dim TempArray() As Boolean
Dim NewArray() As Variant
Dim i As Integer
Dim j As Integer

ReDim TempArray(UBound(array2))

For i = 0 To UBound(array2)
For j = 0 To UBound(array1)
If array2(i) = array1(j) Then
TempArray(i) = True
End If
Next j
Next i

j = 0
For i = 0 To UBound(TempArray)
If Not TempArray(i) Then
ReDim Preserve NewArray(j)
NewArray(j) = array2(i)
j = j + 1
End If
Next i

Regards
Rowan

"Herbert Chan" wrote:

Hello,

I've two lists of data in array in VBA.

How do I exclude the data in array1 from array2 so that I will be left with
an array2 that does not contain any number in array1?

I need this function in VBA.

Thanks.

Herbert