Check if cell value is found in a seperate range of values

W

wilby31

How can I check if a cell's value is found within the values of a range
of values?

For instance:

In the range from say A3:A8 = [3,3,4,5,1,3]
A1 = 3

I want the VBA function to return TRUE.

Something similar to this

Function InRange(Range1 As Range, Range2 As Range) As Boolean
' returns True if Range1 is within Range2
Dim InterSectRange As Range
Set InterSectRange = Application.Intersect(Range1, Range2)
InRange = Not InterSectRange Is Nothing
Set InterSectRange = Nothing
End Function


But base it's check on values, not just addresses.

Thanks a million!
 
B

Bob Phillips

Function InRange(Range1 As Range, Range2 As Range) As Boolean
' returns True if Range1 is within Range2
InRange = Application.CountIf(Range2, Range1) > 0
End Function

if you must use VBA.

You could just use a worksheet formula of

=COUNTIF(A3:A8,A1)>0

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top