# Return true if all values are found in an array

#### yinkajewole

##### Active Member
How can i return as true when all my values are all found in an array?

### Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

#### theBardd

##### Rules violation
Assuming your array is in A1:A6, and the values in B1:B3, you could use this array formula

Code:
``=COUNT(MATCH(B1:B3,A1:A6,0))=COUNT(B1:B3)``

#### yinkajewole

##### Active Member
Assuming your array is in A1:A6, and the values in B1:B3, you could use this array formula

Code:
``=COUNT(MATCH(B1:B3,A1:A6,0))=COUNT(B1:B3)``
i'm sorry, i mean in vba

#### theBardd

##### Rules violation
In VBA, do you want it as part of a bigger routine, or do you want a UDF that returns true or false to the worksheet.

#### yinkajewole

##### Active Member
i like to have it as a function as boolean

#### theBardd

##### Rules violation
Code:
``````Public Function MatchAll(ByRef Target As Range, ByRef Values As Range) As Boolean
Dim cell As Range

MatchAll = True
For Each cell In Values.Cells

If IsError(Application.Match(cell.Value, Target, 0)) Then

MatchAll = False
Exit Function
End If
Next cell
End Function``````