Notifications
Clear all

UserForm - Formato Date para Número

2 Posts
1 Usuários
0 Reactions
1,524 Visualizações
(@brunoafs)
Posts: 195
Reputable Member
Topic starter
 

Boa tarde pessoal,

Estou tentando que um Textbox me retorne o valor em numeral ao invés do formato de data.

Alguém me da um help.

Private Sub CommandButton1_Click()

MsgBox (TextBox1.Value & "-" & TextBox2.Value)

End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

TextBox1.MaxLength = 10 'Permite digitar no máximo 10 caracteres

Select Case KeyAscii

Case 8 'Aceita o BACK SPACE

Case 13: SendKeys "{TAB}" 'Emula o TAB

Case 48 To 57

If TextBox1.SelStart = 2 Then TextBox1.SelText = "/" 'insere barra ao digitar dia

If TextBox1.SelStart = 5 Then TextBox1.SelText = "/" 'insere barra ao digitar mes

Case Else: KeyAscii = 0 'Ignora os outros caracteres

End Select

End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not IsDate(TextBox1) And TextBox1 <> "" Then 'Valida Data

MsgBox "Data inválida"

TextBox1 = ""

Cancel = True

End If

End Sub
 
Postado : 13/12/2019 1:55 pm
(@brunoafs)
Posts: 195
Reputable Member
Topic starter
 

Resolvido:

Private Sub CommandButton1_Click()

If Me.TextBox2.Text = "" Then

    MsgBox "Digite uma posição!", vbCritical

Else

Planilha1.Cells(4, 2).Value = TextBox2.Value & "-" & Format(TextBox1.Value, 0)
Planilha1.Cells(1, 1).Value = TextBox2.Value

Call carregarDados

Unload Me

End If
End Sub
 
Postado : 16/12/2019 7:31 am