I have created a VBA form to enter data into a table. one of the data fields is a date, but it keeps entering the data as mm/dd/yyyy, but I need it to be entered as dd/mm/yyyy. If I change the column to “text” it shows how I want it, but when I use “sort” the date is sorts by number descending not date descending. Is there a way to change the date to dd/mm/yyyy?
—- My current code is; —-
`Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("ClientData")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
Worksheets("ClientData").Unprotect Password:="Password"
' .Unprotect Password:="Password"
.Cells(iRow, 1).Value = Me.txtDate.Value
.Cells(iRow, 2).Value = Me.txtStarttime.Value
.Cells(iRow, 3).Value = Me.txtEndtime.Value
.Cells(iRow, 4).Value = Me.txtTotal.Value
.Cells(iRow, 5).Value = Me.txtProgress.Value
.Cells(iRow, 6).Value = Me.txtStaff.Value
' .Protect Password:="Password"
Worksheets("ClientData").Protect Password:="Password"
End With
'clear the data
Me.txtDate.Value = ""
Me.txtStarttime.Value = ""
Me.txtEndtime.Value = ""
Me.txtTotal.Value = ""
Me.txtProgress.Value = ""
Me.txtStaff.Value = ""`
End Sub
New contributor
Adam Green is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1