2
I created a database in Excel that should accept only 1 CPF. So I created the following function that checks and prevents repeated entries from being entered.
Function verifica_cpf(cpf As Integer) As Boolean
Dim i As Integer, intValueToFind As Long, x As Boolean
cpf = False
intValueToFind = Range("i3").Value
Sheets("Banco de Dados").Select
NumRows = Range("A2", Range("A2").End(xlDown)).Rows.Count
For i = 3 To NumRows
If Cells(i, 1).Value = intValueToFind Then
MsgBox ("CPF já cadastrado na linha " & i & vbNewLine & "Dados não inseridos no banco")
x = True
End If
Next i
Return cpf ' Esta linha apresenta o erro de "fim de instrução esperado" ao compilar
End Function
When the code was inside my main macro, it worked smoothly. Mistakes started when I migrated her to a separate function to get more organized.
In the main sub it is called as follows:
Private Sub Cadastrar()
Sheets("Cadastrar").Select
Dim cpf = verifica_cpf() ' Esta linha apresenta o erro de "fim de instrução esperado" ao compilar
.
.
.
end sub