To all those VBA experts out there, I've written a simple macro in
VBA. The purpose is to alert the user if they encounter a value that
isn't currently in an array. They way I did this is that I compared
the value to each piece of the array within a nested loop. Is there a
way to determine if the value is in the array without having to compare
each piece of the array. If so, what's the function.
Thanks in advance for any help.
GregDoes upper/lower case matter?
If no:
dim myArr as Variant
dim myVal as Variant
dim res as variant
myarr = array(quot;aquot;,quot;bquot;,quot;xyzquot;,1,3,6)
myval = quot;xyzquot; 'or whatever
res = application.match(myval,myarr,0)
if isnumber(res) then
msgbox quot;It's in the array
else
msgbox quot;it's notquot;
end if
Greg wrote:
gt;
gt; To all those VBA experts out there, I've written a simple macro in
gt; VBA. The purpose is to alert the user if they encounter a value that
gt; isn't currently in an array. They way I did this is that I compared
gt; the value to each piece of the array within a nested loop. Is there a
gt; way to determine if the value is in the array without having to compare
gt; each piece of the array. If so, what's the function.
gt;
gt; Thanks in advance for any help.
gt;
gt; Greg
--
Dave Peterson
Dave,
Thanks. That woked, although I had to replace isnumber with isnumeric.
GregOops. Sorry.
Glad you got it working!
Greg wrote:
gt;
gt; Dave,
gt;
gt; Thanks. That woked, although I had to replace isnumber with isnumeric.
gt;
gt; Greg
--
Dave Peterson
- Oct 22 Sun 2006 20:10
Comparing An Array in VBA
close
全站熱搜
留言列表
發表留言