VBA Filter Function

0

I'm using the code below to check if an element is in an array related to a Range. It turns out that in some cases the result is = 0 showing that it exists, but it does not exist.

What's wrong? Instead of this function should I go through the matrix through a Loop ?

If UBound(Filter(canc, Pl.Cells(x, "b").Value, , vbBinaryCompare)) <> -1
    
asked by anonymous 18.04.2018 / 16:02

1 answer

1

I already did this search function with LOOP using FOR in the Matrix. Just enter the word to be found and the table where the search will be performed.

Function LoopNaTabela(palavra As String, Tb)
Dim Dimenssao As Byte, i As Long, j As LongOn Error Resume Next
If IsError(UBound(Tb, 2)) Then Dimensao = 1 Else Dimensao = 2
On Error GoTo 0
Select Case Dimensao
    Case 2
        For i = LBound(Tb, 1) To UBound(Tb, 1)
            For j = LBound(Tb, 2) To UBound(Tb, 2)
                If Tb(i, j) = palavra Then LoopNaTabela = True: Exit Function
            Next j
        Next i
End Select
End Function

In this format it will go through the entire matrix in search of the specific word, I have never had performance problems with it.

If you'd like to try other ways, at this link: Check word

It has plenty of content and example on the theme

    
18.04.2018 / 16:31