Ash Sooraj
Ash Sooraj

Reputation: 55

date format getting changed

I need to copy date in format "dd-mm-yy" to a cell . But while entering at cell it is in "mm-dd-yy" format,I believe this happens when date is less than 12

Worksheets(1).Cells(i, 40).Value = Format(TextBox3.Value, "dd-mm-yy HH:mm:ss")

Worksheets(1).Cells(i, 40).Value = TextBox3.Value

if I enter 03-09-2019 in textbox and press submit .It should be in 03-09-2019 itself.

Instead it is changing to 09-03-2019(09-march-19).column format is also in "dd-mm-yy" format .it was working fine when date was "30-08-19"

Upvotes: 0

Views: 85

Answers (1)

TourEiffel
TourEiffel

Reputation: 4424

Maybe you can give this a try (had the same issue as yours the way to solve is to save value in date var):

Sub tryme()

    Dim TextBoxVal As Date

    If Not TextBox3.Value = vbNullString Then
        If IsEmpty(TextBox3.Value) = False Then



TextBoxVal = TextBox3.Value
TextBoxVal = Format(TextBox3.Value, "dd-mm-yy HH:mm:ss")

With ActiveWorkbook.Worksheets(1).Cells(i, 40)
   TextBoxVal = format(Month(.Value) & "/" & Day(.Value) & "/" & Year(.Value), "dd/mm/yyyy")

End With
Worksheets(1).Cells(i, 40).Value = TextBoxVal
        End If
    End If

End Sub

Upvotes: 1

Related Questions