Comparing An Array in VBA

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

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.

Greg
 
Does upper/lower case matter?

If no:

dim myArr as Variant
dim myVal as Variant
dim res as variant

myarr = array("a","b","xyz",1,3,6)
myval = "xyz" 'or whatever

res = application.match(myval,myarr,0)
if isnumber(res) then
msgbox "It's in the array
else
msgbox "it's not"
end if
 

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

Similar Threads

VBA arrays 3
Shape Arrays VBA 0
Set values in an Array 9
Array Formula 11
Unique values in an array. 2
Value match with an array 1
Excel Trying to code an Array Function in VBA Excel to works as a MaxIF 3
Compare Strings 4

Back
Top