Checagem de duplicadas forms VBA
Enviado: 11 Jan 2022 às 08:55
Bom dia pessoal!
Estou tentando fazer uma verificação na minha planilha, para que o usuário não cadastre o mesmo valor 2 vezes, mas meu código não está funcionando.
Alguém poderia me ajudar??
Segue abaixo meu código:
Private Sub botao_aplicar_Click()
linha2 = Cells(Rows.Count, 1).End(xlUp).Row + 1
lin = 8
While lin < linha2
If Cells(lin, 4) = Val(autuacao.Value) Then
MsgBox ("Multa já cadastrada, mesmo número de autuação")
Exit Sub
End If
lin = lin + 1
Wend
Cells(linha2, 1) = status.Value
Cells(linha2, 2) = placa.Value
Cells(linha2, 3) = data.Value
Cells(linha2, 4) = autuacao.Value
Cells(linha2, 5) = autuacaoIdentificada.Value
Cells(linha2, 6) = dataVencimento.Value
Cells(linha2, 7) = motorista.Value
Cells(linha2, 8) = motivo.Value
Cells(linha2, 9) = local_caixa.Value
Cells(linha2, 10) = vencimento1.Value
Cells(linha2, 11) = vencimento2.Value
Cells(linha2, 12) = valor.Value
Cells(linha2, 13) = obs.Value
Range("A8:K8").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Unload Diretoria
End Sub
Estou tentando fazer uma verificação na minha planilha, para que o usuário não cadastre o mesmo valor 2 vezes, mas meu código não está funcionando.
Alguém poderia me ajudar??
Segue abaixo meu código:
Private Sub botao_aplicar_Click()
linha2 = Cells(Rows.Count, 1).End(xlUp).Row + 1
lin = 8
While lin < linha2
If Cells(lin, 4) = Val(autuacao.Value) Then
MsgBox ("Multa já cadastrada, mesmo número de autuação")
Exit Sub
End If
lin = lin + 1
Wend
Cells(linha2, 1) = status.Value
Cells(linha2, 2) = placa.Value
Cells(linha2, 3) = data.Value
Cells(linha2, 4) = autuacao.Value
Cells(linha2, 5) = autuacaoIdentificada.Value
Cells(linha2, 6) = dataVencimento.Value
Cells(linha2, 7) = motorista.Value
Cells(linha2, 8) = motivo.Value
Cells(linha2, 9) = local_caixa.Value
Cells(linha2, 10) = vencimento1.Value
Cells(linha2, 11) = vencimento2.Value
Cells(linha2, 12) = valor.Value
Cells(linha2, 13) = obs.Value
Range("A8:K8").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Unload Diretoria
End Sub