Dear experts,
I am trying to enter a European date in my userform but the result is always in US date format.
Here is the code I got from an internet template:
____________________________________________
Private Sub cmdEnter_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Forester X fuel")
''find first empty row in database
'revised code to avoid problems with Excel tables in newer versions
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a date
If Trim(Me.txtDate.Value) = "" Then
Me.txtDate.SetFocus
MsgBox "Please enter the date"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtDate.Value
ws.Cells(iRow, 2).Value = Me.txtOdo.Value
ws.Cells(iRow, 3).Value = Me.txtLitres.Value
ws.Cells(iRow, 4).Value = Me.txtCost.Value
ws.Cells(iRow, 7).Value = Me.txtLocation.Value
'copy the provider to the database
If frmFuel.obnBP.Value = True Then
ws.Cells(iRow, 6).Value = "BP"
Else
ws.Cells(iRow, 6).Value = "Caltex"
End If
'clear the data
Me.txtDate.Value = ""
Me.txtOdo.Value = ""
Me.txtLitres.Value = ""
Me.txtCost.Value = ""
Me.txtLocation.Value = ""
Me.obnBP.Value = False
Me.obnCaltex.Value = False
Me.txtDate.SetFocus
End Sub
___________________________________________
My spreadsheet is set to "ddd dd mmm yyyy" and I can enter a date (via the cell) in many ways, it always gets it right (eg. 1-9-12 or 1/9/12 or 1-9-2012 gives me "Sat 01 Sep 2012).
Now how can I tell VBA that the text I enter in my userform is just a string, hoping that it will be converted to my custom date format in my spreadsheet?
Many thanks for the help. Note: Complete VBA novice!
Patrick
I am trying to enter a European date in my userform but the result is always in US date format.
Here is the code I got from an internet template:
____________________________________________
Private Sub cmdEnter_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Forester X fuel")
''find first empty row in database
'revised code to avoid problems with Excel tables in newer versions
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a date
If Trim(Me.txtDate.Value) = "" Then
Me.txtDate.SetFocus
MsgBox "Please enter the date"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtDate.Value
ws.Cells(iRow, 2).Value = Me.txtOdo.Value
ws.Cells(iRow, 3).Value = Me.txtLitres.Value
ws.Cells(iRow, 4).Value = Me.txtCost.Value
ws.Cells(iRow, 7).Value = Me.txtLocation.Value
'copy the provider to the database
If frmFuel.obnBP.Value = True Then
ws.Cells(iRow, 6).Value = "BP"
Else
ws.Cells(iRow, 6).Value = "Caltex"
End If
'clear the data
Me.txtDate.Value = ""
Me.txtOdo.Value = ""
Me.txtLitres.Value = ""
Me.txtCost.Value = ""
Me.txtLocation.Value = ""
Me.obnBP.Value = False
Me.obnCaltex.Value = False
Me.txtDate.SetFocus
End Sub
___________________________________________
My spreadsheet is set to "ddd dd mmm yyyy" and I can enter a date (via the cell) in many ways, it always gets it right (eg. 1-9-12 or 1/9/12 or 1-9-2012 gives me "Sat 01 Sep 2012).
Now how can I tell VBA that the text I enter in my userform is just a string, hoping that it will be converted to my custom date format in my spreadsheet?
Many thanks for the help. Note: Complete VBA novice!
Patrick