Determine if item is in a range of items
Thanks
"Gary''s Student" wrote:
You can try to Find the value in the range:
Sub Macro1()
Set r = Range("A1:D4,G10:H11")
On Error GoTo qwerty
r.Find(What:="1", After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
MsgBox ("it is there")
Exit Sub
qwerty:
MsgBox ("it is not there")
End Sub
--
Gary''s Student - gsnu200770
"Mark" wrote:
I'm wanting to check if a value in one cell is in a range of other cells.
(For example, A1 contains "dog" and B1 through B10 contains a list of various
animals. I want to know if "dog" in the list.) I know I can program a loop
and compare item-by-item, but I'm guessing there's a couple of one-liners
that will do it more efficiently, like loading the range of values in a
collection then inquiring if the single cell value is in the collection.
Cannot seem to find anything in Help to steer me in the right direction.
|