Search for Variable in Array

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am running a loop, where i go down a list of part numbers, and i need to check each number against a variable list, and if they are in there, it returns yes, and if not, returns a no.

VBA Code:
Sheets("77 surplus").Select
                  
    Dim arr As Variant
                  
        arr = Range("I2:I122")
              
        finalrow = Cells(Rows.Count, 1).End(xlUp).Row
        
            For i = 2 To finalrow
        
            Cells(i, 1).Value = partNumber
            
            '**if partNumber variable exists in the list of numbers in arr then**
                'cells(i,4).value = "Y"
            'else
                'cells(i,4).value = "N"
            'End If
                
            Next i

How can i search that list in the array?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
How about
VBA Code:
    Dim Dic As Object
    Dim Cl As Range
    
    Sheets("77 surplus").Select
    
    Set Dic = CreateObject("Scripting.dictionary")
    For Each Cl In Range("I2:I122")
         Dic.Item(Cl.Value) = Empty
    Next Cl
    For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Dic.exists(Cl.Value) Then
             Cl.Offset(, 3).Value = "Y"
         Else
             Cl.Offset(, 3).Value = "N"
         End If
     Next Cl
 
Upvote 0
Are you running this on a Mac?
 
Upvote 0
the error message happened on this line:

Set Dic = CreateObject("Scripting.dictionary")
 
Upvote 0
Goto the syswow64 folder C:\Windows\SysWOW64
and check that you have a file called scrrun.dll
 
Upvote 0
yes i do

1575668522307.png
 
Upvote 0
Interesting.
In the VB editor > Tools > References > scroll down & check "Microsoft Scripting Runtime" (make sure you check the box, rather than just select the line)
Does it let you do that?
If so try running the code again. What happens?
 
Upvote 0
it let me select it, it still shows as checked, i saved, closed out and went back in, and still got the same error message

1575669389889.png
 
Upvote 0

Forum statistics

Threads
1,215,337
Messages
6,124,340
Members
449,155
Latest member
ravioli44

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