vendredi 15 janvier 2021

Excel VBA Labelling Data

I'm currently trying to label data from a table. The table contains a column that gives a description of an event. Those descriptions have Keywords that could be used to label the event itself. So I just need to check which keyword each description contains to label it. Therefore, I tried to create a function with a simple ElseIf statement to check if the description contains a keyword like this:

Public Function Teste(ByVal Gasto As String) As String

' Atualizar Calc
Application.Volatile
    
If IsError(Application.WorksheetFunction.Search("DULCE", Gasto)) <> True Then
    
    Teste = "RETIRADA DULCE"
    
ElseIf IsError(Application.WorksheetFunction.Search("SALARIO", Gasto)) <> True Then
    
    Teste = "FOLHA DE PAGAMENTO"
    
End If
End Function

Everything works well for the first condition, however, when the first condition is not found and we go to the second condition test it raises a value error. Could someone help me out with this one? Any help is appreciated. :)

Aucun commentaire:

Enregistrer un commentaire