glaubermoraes93
14-05-2015 14:53:15
Pessoal preciso de uma ajuda.
estou iniciando em VBA e estou com uma dificuldade, preciso que o usuario preencha o CNPJ e quando ele der TAB ou Enter o sistema compare com o cnpj da planilha, tendo como chave a matricula do prestador.
Segue o código.
Private Sub txtcnpj_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
Dim lngRow As Long
Dim CNPJ As Currency
Dim Prestador As Currency
Dim c As Range
If Me.txtcnpj.Text = "" Then
MsgBox "Favor Preencher o CNPJ", vbOKOnly, "Atenção"
Me.txtcnpj.SetFocus
Else
Prestador = Me.txtCPProtocolador.Value
CNPJ = Me.txtcnpj.Value
With ThisWorkbook.Worksheets("Prestadores")
.Activate
Set c = .Range("A1:A10").Find(Prestador, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
If Prestador = c.Value And CNPJ = c.Offset(0, 9).Value Then
Me.frmdadosfiscais.Visible = True
End If
Else
MsgBox "CNPJ incorreto", 64, " Atenção"
Me.txtcnpj.Text = ""
Me.txtcnpj.SetFocus
End If
End With
End If
End If
End Sub
e no c.value apresenta a mensagem "a variavel do objeto ou a variavel do bloco with não foi definida"
estou iniciando em VBA e estou com uma dificuldade, preciso que o usuario preencha o CNPJ e quando ele der TAB ou Enter o sistema compare com o cnpj da planilha, tendo como chave a matricula do prestador.
Segue o código.
Private Sub txtcnpj_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
Dim lngRow As Long
Dim CNPJ As Currency
Dim Prestador As Currency
Dim c As Range
If Me.txtcnpj.Text = "" Then
MsgBox "Favor Preencher o CNPJ", vbOKOnly, "Atenção"
Me.txtcnpj.SetFocus
Else
Prestador = Me.txtCPProtocolador.Value
CNPJ = Me.txtcnpj.Value
With ThisWorkbook.Worksheets("Prestadores")
.Activate
Set c = .Range("A1:A10").Find(Prestador, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
If Prestador = c.Value And CNPJ = c.Offset(0, 9).Value Then
Me.frmdadosfiscais.Visible = True
End If
Else
MsgBox "CNPJ incorreto", 64, " Atenção"
Me.txtcnpj.Text = ""
Me.txtcnpj.SetFocus
End If
End With
End If
End If
End Sub
e no c.value apresenta a mensagem "a variavel do objeto ou a variavel do bloco with não foi definida"