Quick Help Plz

momo3

New Member
Joined
Jul 25, 2019
Messages
1
Hello,
I am starting with VBA and I'd like to know if it was possible to use list from a worksheet inside the code. I wouldn't want to create an array as my list is pretty long. I would like to have an if statement that goes like:

If Range("A1").Value IN [a liste of value inside the worksheet] Then
...

Is there a way to do that?
Thanks in advance!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi & welcome to MrExcel.
One way to do that is with a Dictionary, like
Code:
Sub momo3()
   Dim Ary As Variant
   Dim i As Long
   Dim Dic As Object
   Dim Cl As Range
   
   Ary = Sheets("List").Range("A1").CurrentRegion.Value2
   Set Dic = CreateObject("scripting.dictionary")
   For i = 1 To UBound(Ary)
      Dic.Item(Ary(i, 1)) = Empty
   Next i
   With Sheets("Sheet1")
      For Each Cl In .Range("A1", .Range("A" & Rows.Count).End(xlUp))
         If Dic.Exists(Cl.Value) Then
            'do something
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
Welcome to the forum

Try this

Code:
Sub dam_test1()
  Dim r As Range, f As Range
  Set r = Range("B1", Range("B" & Rows.Count).End(xlUp))
  Set f = r.Find(Range("A1"), , xlValues, xlWhole)
  If Not f Is Nothing Then
    MsgBox "exists, do some"
  Else
    MsgBox "Does not exists"
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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