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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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
What IsNumeric do eaxtly here? Some additional checking?

Hi, Match() will return an error is the element is not present in the array or it's numerical position if it is. So if its a number it's in the array else it's an error and it's not.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

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