Excel VBA changes the date format to mm/dd/yyyy

Asked

Viewed 961 times

0

I’m developing a spreadsheet on Excel using the VBA, which will function as a "micro-system" of registration.

I have the following problem: every time I type the date into the cell Cad_0, for example, Excel changes the format to mm/dd/yyyy.

In the same spreadsheet I’m already using a code so that the Excel change the text typed in lower case to upper case.

If I delete that code, Excel to change the date format.

  • How do you change these digits? Could you enter the code you are using? Editing the question with the code.

1 answer

1

Following model below, converting dates:

inserir a descrição da imagem aqui

Dim CData As Date  
Dim CData2 As Date  

{'--- MODELO 01}  
Sub DataCompra1()  

    [C8].Select
    CData = [C8].Value

    If CData = "0" Then
        MsgBox "INFORME A DATA"
        'Exit Sub '--- ESTA FUNÇÃO PARA O SCRIPT, CASO QUEIRA UTILIZAR DESCOMENTE A LINHA
    Else
        ActiveCell.Value = ""
        Selection.Offset(0, 2).Select
        ActiveCell.Value = CData

    End If

End Sub

{'--- MODELO 02}  
Sub DataCompra2()  

    Dim CData As Date
    Dim CHora As Date

    dt = [C8].Value
    'fmt = [C8].Value
    CData = Format(dt)
    CHora = Format(Now)
    'Format (fmt)

    [E8].Value = CData
    [E9].Value = CHora

End Sub

Sub LimparData()

[C8].Value = ""
[E8].Value = ""

End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.