Check out is element in the array (using Filter)

Nykyta

New Member
Joined
Aug 14, 2014
Messages
43
I have array like next:
Code:
arr=Array("ws2","ws3","ws11")
Function to checkout is element in array is:
Code:
Function IsInArray(valToBeFound As Variant, Arr As Variant) As Boolean
IsInArray = (UBound(Filter(Arr, valToBeFound)) > -1)
End Function
When checking out "ws1" — it is found at the 3rd place in array (weird of course).
1. Is it attitude of Filter used in func IsInArray?
2. Is it global bug in arrays?
3. How to solve this problem?

Thanks in advance, Nyk.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi, I think it's the way filter works full stop.

You could try this alternative:
Code:
Function IsInArray(valToBeFound As Variant, Arr As Variant) As Boolean
  IsInArray = IsNumeric(Application.Match(valToBeFound, Arr, 0))
End Function
 
Upvote 0
Thank you very much FormR. Simple but nice one.
Match returned positiion anyway. What IsNumeric do eaxtly here? Some additional checking?
 
Upvote 0

Forum statistics

Threads
1,215,155
Messages
6,123,332
Members
449,098
Latest member
thnirmitha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top