Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
#68624
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
Avatar do usuário
Por fcarlosc2018
Posts Avatar
#68625
Bom-dia

Segue um exemplo. A verificação é feita ao sair da TextBox.
Código: Selecionar todos
Private Sub autuacao_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If WorksheetFunction.CountIf(Range("A1:A100"), autuacao.Value) > 0 And autuacao <> "" Then
        MsgBox "Multa já cadastrada, mesmo número de autuação", vbInformation, "AVISO"
        Cancel = True
        autuacao.SetFocus
End If

End Sub
Att,
Francisco
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord