Hi,
I am writing a program in Excel Macro, where I need to create an array and then have to check wheather an element exists or not in that array.
I have created the array as follows -

Dim tmpArr(1 to 10) as Integer
tmpArr = Array(2,4,6,8,10)

Now, i can't find any clue how to check a value 5 is exists in the array or not.
Please suggest.

Use something like -

If 5 <> tmpArr Then
   'Your error trapping here
End If

You can also do it as in -

If Not tmpArr = Value Then 'Value in this case is 5
   'Error trapping here
End If

Use either the Join Function and InStr to find ",5," or use a for loop to go from LBound to UBound and test for the value...

Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.