Array question

jpen

Active Member
Joined
Jun 19, 2002
Messages
384
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,523
Office Version
365
Platform
Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,523
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,078,435
Messages
5,340,256
Members
399,361
Latest member
Linford

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top