Highlight Textbox if the loaded value is equal in the worksheet

Asked

Viewed 739 times

2

In a Registration Form when clicking search the textbox are completed. And if any of these Textbox has a value that is on plan1 from the "AS" column then this Textbox has the highlighted text (e.g. Green). I got a code but it’s not working.

In the module:

Function ProcuraCheque(Cheque As String) As Boolean

    Dim Intervalo, Celula As Range

    Set Intervalo = Planilha1.Range("A1:B10") 'Informe aqui o intervalo onde estão os dados

    For Each Celula In Intervalo
        If Celula.Value = Cheque Then
        ProcuraCheque = True 'Verdadeiro se encontrado
        Exit For
        End If
    Next Celula

End Function

Não estou conseguindo chamr a função no evento Change ou AfterUpdate da TextBox, passando na função o valor da TextBox (tipo TextBox1.Value...). Caso ela seja verdadeira (If ProcuraCheque(Textbox1.Value)=True), o propriedade ForeColor da TextBox assume o valor vbRed, e se for Falso, vbBlack.

Private Sub TextAI1_Change()

If TextAI1.Value = "FunctionProcuraCheque" Then

    Me.TextAI1.ForeColor = &HFF0000
Else

    Me.TextAI1.ForeColor = &HFF&

End If
End Sub

1 answer

1


@ludehenrique2cia, See that in this part of the code you are comparing the "content" of the Textbox with the "name of the function", unless the name of the function is in the text of the Textbox, what comes after the "Then" will never be executed, only the part after the "Else" will be executed.

If TextAI1.Value = "FunctionProcuraCheque" then
    Me.TextAI1.ForeColor = &HFF0000
else
    Me.TextAI1.ForeColor = &HFF& '<== SOMENTE ESTA INSTRuÇÃO SERÁ EXECUTADA!
endif

I think what you want is to compare the contents of Textbox with a cell in the spreadsheet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.