Array question

jpen

Active Member
Joined
Jun 19, 2002
Messages
402
I have a array with 500 records and another array with 25 numbers. These 25 numbers are between 1-500.

I want too clear all the records in 500 record array which are not in the 25 records array.

Array1 10, 20, 31, 32, 45, 50
Array2 20, 45

After matching the result for array1 is 0, 20, 0, 0, 45, 0


Thanks for the effort.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about
Code:
Sub jpen()
    Dim Ary1 As Variant, Ary2 As Variant, x
    Dim i As Long
    
    Ary1 = Array(10, 20, 31, 32, 45, 50)
    Ary2 = Array(20, 45)
    With CreateObject("scripting.dictionary")
        For i = 0 To UBound(Ary2)
             .Item(Ary2(i)) = Empty
        Next i
        For i = 0 To UBound(Ary1)
            If Not .exists(Ary1(i)) Then Ary1(i) = 0
        Next i
    End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top