Colega
Bom dia
‘1 Primeiro adicione o código no seu frm_cadastro
‘Observação, altere as txtbox txt_valor_c_bonus e txt_valor_total_lote de acordo com o exemplo colocado na txt_valor
Private Sub txt_dt_rcbto_lote_Change()
txt_dt_rcbto_lote.MaxLength = 10 'Numero máximo de caracteres
'Formatar como Data
Select Case Len(txt_dt_rcbto_lote)
Case Is = 2
txt_dt_rcbto_lote = txt_dt_rcbto_lote & "/"
Case Is = 5
txt_dt_rcbto_lote = txt_dt_rcbto_lote & "/"
End Select
End Sub
Private Sub txt_dt_rcbto_lote_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Aceitar somente números
Dim xVal As String
xVal = "0123456789"
If InStr(xVal, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Private Sub txt_dt_dev_lote_Change()
txt_dt_dev_lote.MaxLength = 10 'Numero máximo de caracteres
'Formatar como Data
Select Case Len(txt_dt_dev_lote)
Case Is = 2
txt_dt_dev_lote = txt_dt_dev_lote & "/"
Case Is = 5
txt_dt_dev_lote = txt_dt_dev_lote & "/"
End Select
End Sub
Private Sub txt_dt_dev_lote_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Aceitar somente números
Dim xVal As String
xVal = "0123456789"
If InStr(xVal, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Private Sub txt_valor_AfterUpdate()
With frm_cadastro.txt_valor 'Escolha um dos formatos de valores
'If IsNumeric(.Value) Then .Value = Format(.Value, "#,##0.00") '--------Formato de valores SEM o cifrão
If IsNumeric(.Value) Then .Value = Format(.Value, "R$ #,##0.00") '--------Formato de valores COM o cifrão
End With
End Sub
‘Depois altere no botão gravar a parte do código
'Carregar os dados digitados nas caixas de texto para a planilha
x = txt_dt_rcbto_lote.Value
y = Format(x, "dd/mm/yyyy")
ActiveCell.Offset(0, 0).Value = y
ActiveCell.Offset(0, 1).Value = txt_num_lote.Value
ActiveCell.Offset(0, 2).Value = txt_referencia.Value
ActiveCell.Offset(0, 3).Value = txt_cliente.Value
ActiveCell.Offset(0, 4).Value = txt_pedido.Value
ActiveCell.Offset(0, 5).Value = txt_qtde_rcbto.Value
ActiveCell.Offset(0, 6).Value = txt_descricao.Value
ActiveCell.Offset(0, 7).Value = txt_valor.Value
ActiveCell.Offset(0, 8).Value = txt_fornecedor.Value
ActiveCell.Offset(0, 9).Value = txt_nf_rcbto.Value
i = txt_dt_dev_lote.Value
j = Format(i, "dd/mm/yyyy")
ActiveCell.Offset(0, 10).Value = j
ActiveCell.Offset(0, 11).Value = txt_nf_dev.Value
ActiveCell.Offset(0, 12).Value = txt_qtde_dev.Value
ActiveCell.Offset(0, 13).Value = txt_cont_fornec.Value
ActiveCell.Offset(0, 14).Value = txt_bonus.Value
ActiveCell.Offset(0, 15).Value = txt_valor_c_bonus.Value
ActiveCell.Offset(0, 16).Value = txt_valor_total_lote.Value
‘A respeito da necessidade número 3, de alteração. O Ideal seria que você tivesse um formulário para alterações. Mas você pode adicionar um botão com o nome bt_gravar_Alteracao e dentro do botão adicionar a mesma rotina do gravar, só que essa sem a pesquisa de última linha vazia, apenas alterando a linha ativa. Por exemplo;
‘BOTÃO DE ALTERAÇÃO
'Descarrega os dados do formulário na planilha.
x = txt_dt_rcbto_lote.Value
y = Format(x, "dd/mm/yyyy")
ActiveCell.Offset(0, -1).Value = y
ActiveCell.Offset(0, 0).Value = txt_num_lote.Value
ActiveCell.Offset(0, 1).Value = txt_referencia.Value
ActiveCell.Offset(0, 2).Value = txt_cliente.Value
ActiveCell.Offset(0, 3).Value = txt_pedido.Value
ActiveCell.Offset(0, 4).Value = txt_qtde_rcbto.Value
ActiveCell.Offset(0, 5).Value = txt_descricao.Value
ActiveCell.Offset(0, 6).Value = txt_valor.Value
ActiveCell.Offset(0, 7).Value = txt_fornecedor.Value
ActiveCell.Offset(0, 8).Value = txt_nf_rcbto.Value
i = txt_dt_dev_lote.Value
j = Format(i, "dd/mm/yyyy")
ActiveCell.Offset(0, 9).Value = j
ActiveCell.Offset(0, 10).Value = txt_nf_dev.Value
ActiveCell.Offset(0, 11).Value = txt_qtde_dev.Value
ActiveCell.Offset(0, 12).Value = txt_cont_fornec.Value
ActiveCell.Offset(0, 13).Value = txt_bonus.Value
ActiveCell.Offset(0, 14).Value = txt_valor_c_bonus.Value
ActiveCell.Offset(0, 15).Value = txt_valor_total_lote.Value
Atenciosamente
Tov Elen Shau