Converter formato de data

lima.luiz

18-04-2019 14:02:31

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?

webmaster

18-04-2019 16:15:25

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]

webmaster

18-04-2019 16:16:33

lima.luiz

18-04-2019 17:52:46

Obrigado, amigos. Funcionou!!! :D

andril

07-01-2020 05:40:58

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!

andril

07-01-2020 05:52:43

Ops, respondi no tópico errado, rsrs.