How to exclude a list of number from another list?
This solution does not use any objects/references:
Sub array2Withoutarray1()
array1 = Array(31.4, 41.1, 7, 15.4, 47.2, 90.4, 34.5, 58, 29.7, 8.9)
array2 = Array(63.5, 75.3, 7, 1.8, 27.7, 34.5, 24.6, 34.7)
result = Without(array2, array1)
End Sub
Function Without(ByVal Keep As Variant, ByVal Exclude As Variant) As Variant
Keep = "," & Join(Keep, ",")
For i = LBound(Exclude) To UBound(Exclude)
Keep = Replace(Keep, "," & Exclude(i), "")
Next
If "," = Mid(Keep, 1, 1) Then Keep = Mid(Keep, 2)
Without = Split(Keep, ",")
End Function
"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
|