How to find if an array contains a string Using the UDF from this answer I am trying to test whether each cell in column C is in the aCheck
array. Eventually I would like to cut the row the cell is on (if confirmed to be within the array) and paste that row to a new sheet, but as of right now I receive a type mismatch error
or a By Ref error
with the UDF at times when I try and debug.
I've modified the function I found in the above answer to be ByVal arr As Range
when it originally was arr As Variant
The acheck(aCheck_Row, 1)
expression is defined as a string
in the locals window and aSelection
does reference column C when I view the expression within the locals window, also the Values2
expression does literally list the worksheet values on the worksheet..
Like I've mentioned I'm messed around with ByVal vs ByRef and changing the object in the function from an array to a range.. I've also noted the above answer suggests the answer only works for a 1D array which I believe I have.
How could I test whether a value in Column C is in array acheck(aCheck_Row, 1)
or if that cannot be done how can I test if a value in Column C is in range aSelection
?
Function IsInArray(stringToBeFound As String, ByVal arr As Range) As Boolean
IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function
LR = Range("C1500").End(xlUp).Row
ReDim acheck(1 To LR)
For i = 2 To LR
aCheck_Row = aCheck_Row + 1
acheck(aCheck_Row, 1) = CStr(cells(i, cA))
Next i
For Each cell In aSelection
If IsInArray(cell.Value, aSelection) Then
cell.Style = "Accent1"
End If
Next cell