Excel VBA check the contents of two cells

2

Good morning.

I'm trying to create some modules in excel to help me at work, and one of the modules I created exchanges all the accented letters and special characters of a cell with unaccented letters and substitutes for the special characters. See example below:

Cell A1= "Essa peça de roupa custa R$59,99 somente este mês."
Cell A2= "Essa peca de roupa custa RS59,99 somente este mes."

I need to create a module that checks if what is in "Cell" A1 conforms to the "cell" A2 even without accents and special characters.

    
asked by anonymous 13.03.2017 / 12:47

1 answer

1

I suggest you create a function with character override rules with accents. I do not know how you wrote this code, but I imagined something like this, structured as a function for better handling of variables:

Public Function SemAcentos(t As String)

    t = Replace(t, "ç", "c")
    t = Replace(t, "à", "a")
    t = Replace(t, "á", "a")
    t = Replace(t, "ã", "a")
    t = Replace(t, "â", "a")
    t = Replace(t, "é", "e")
    t = Replace(t, "ê", "e")
    t = Replace(t, "í", "i")
    t = Replace(t, "õ", "o")
    t = Replace(t, "ó", "o")
    t = Replace(t, "ú", "u")

    ' ...todas as demais regras de substituição de caracteres especiais!!!

    SemAcentos = t

End Function

In this way, you can remove the accents of Cell A1 and immediately compare it to Cell A2, something like this:

Sub macro1()

    If SemAcentos(Range("A1").Value) = Range("A2").valuie Then
        MsgBox "Verdadeiro"
    Else
        MsgBox "Falso"
        End If

End Sub

Or, since you created a function, you can use it directly in a cell of the worksheet, using it in combination with the SE formula, for example:

=SE(SemAcentos(A1)=A2;VERDADEIRO;FALSO)
    
21.03.2017 / 16:26