Matching value in Range("A5") against a list of items

teachman

Active Member
Joined
Aug 31, 2011
Messages
321
Hello,

I have a script with an IF Range("A" & r) value is also in a lookup list AND Range("I" & r) THEN do something. I know I can do a bunch of ORs but that doesn't seem particularly neat.

IF Range("A" & r) is in Lookup list named Type AND Range("I" & r) IS NULL Then DoSomething.

Any ideas?

Thanks,

George Teachman
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Where is your lookup list? Is it a range on a spreadsheet? Or is it a VBA array? One of these should work:

Code:
Sub test1()


    r = 10
    
    arr = Array(2, 4, 6, 8)
    If UBound(Filter(arr, Range("A" & r).Value)) >= 0 And Range("I" & r) = "" Then
        x = 1
    End If
    
    If WorksheetFunction.CountIf(Range("P1:P5"), Range("A" & r).Value) > 0 And Range("I" & r) = "" Then
        x = 1
    End If
    
End Sub
 
Upvote 0
The list is a named range, try:

Code:
Sub Match_Value()
  Dim r As Long, f As Range
  For r = 1 To 10
    Set f = Range("Type").Find(Range("A" & r), , xlValues, xlWhole)
    If Not f Is Nothing And Range("I" & r) = "" Then
      'DoSomething
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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