Página 1 de 1
Converter formato de data
Enviado: Qui Abr 18, 2019 11:02 am
por lima.luiz
Bom dia,
preciso de ajuda desse prestativo fórum.
Tenho uma textbox (Plan2.Range("b17") = txtDespacho.Text) que grava a data no formato: dd/mm/aaaa
porém, necessito que converta para o formato de exemplo: 17 DE ABRIL DE 2019
Alguém pode ajudar?
Re: Converter formato de data
Enviado: Qui Abr 18, 2019 1:15 pm
por webmaster
Você pode aplicar a formatação ou na planilha ou no código VBA. No caso, o formato é:
dd \d\e mmmm \d\e yyyy
Se for no VBA:
Código: Selecionar todos
Plan2.Range("B17") = Format(CDate(txtDespacho.Text), "dd \d\e mmmm \d\e yyyy")[\CODE]
Re: Converter formato de data
Enviado: Qui Abr 18, 2019 1:16 pm
por webmaster
Re: Converter formato de data
Enviado: Qui Abr 18, 2019 2:52 pm
por lima.luiz
Obrigado, amigos. Funcionou!!!
Re: Converter formato de data
Enviado: Ter Jan 07, 2020 2:40 am
por andril
Consegui!
Segue fórmula, só colocar no conteúdo VBA da planilha e escolher o range que no meu caso é apenas a célula C5:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim DateStr As String
On Error GoTo EndMacro
If Intersect(Target, Range("C5")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
Application.EnableEvents = False
With Target
If .HasFormula = False Then
Select Case Len(.Formula)
Case 4
DateStr = Left(.Formula, 1) & "/" & _
Mid(.Formula, 2, 1) & "/" & Right(.Formula, 2)
Case 5
DateStr = Left(.Formula, 1) & "/" & _
Mid(.Formula, 2, 2) & "/" & Right(.Formula, 2)
Case 6
DateStr = Left(.Formula, 2) & "/" & _
Mid(.Formula, 3, 2) & "/" & Right(.Formula, 2)
Case 7
DateStr = Left(.Formula, 1) & "/" & _
Mid(.Formula, 2, 2) & "/" & Right(.Formula, 4)
Case 8
DateStr = Left(.Formula, 2) & "/" & _
Mid(.Formula, 3, 2) & "/" & Right(.Formula, 4)
Case Else
Err.Raise 0
End Select
.Formula = DateValue(DateStr)
End If
End With
Application.EnableEvents = True
Exit Sub
EndMacro:
MsgBox "Insira: 1120 para 01/01/2020!"
Range(Target.Address).ClearContents
Application.EnableEvents = True
End Sub
Obrigado e até mais!
Re: Converter formato de data
Enviado: Ter Jan 07, 2020 2:52 am
por andril
Ops, respondi no tópico errado, rsrs.