PDA

View Full Version : Solved: Date Saving Problem



tqm1
06-22-2007, 12:18 AM
Dear Experts

I use following codes to save data from Userform to sheet


Private Sub CommandButton2_Click()
Dim LastRow As Integer, ws As Worksheet
Set wsd = Worksheets("Sheet1")

'find first empty row in database
LastRow = wsd.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'wsd.Cells(LastRow, 2).NumberFormat = "dd/mm/yy;@"

wsd.Cells(LastRow, 1).Value = Me.TextBox1.Value
wsd.Cells(LastRow, 2).Value = Format(Me.TextBox2.Value, "d-m-yy;@")
wsd.Cells(LastRow, 3).Value = Me.TextBox3.Value
End Sub

userform1.textbox2.value=10-04-1975 savesin sheet as 04/10/75
userform1.textbox2.value10-04-1975 savesin sheet as 04/10/1975
userform1.textbox2.value25-12-88 savesin sheet as 25-12-88
userform1.textbox2.value25-12-1988 savesin sheet as 25-12-88

My question is

I use only one type of FORMAT as


Format(Me.TextBox2.Value, "d-m-yy;@")

to save data but sheet shows DATES with different Formats. i.e. 75,1975

How to store Dates with this British format "dd-mm-yy"

Please help

Bob Phillips
06-22-2007, 01:15 AM
Use



wsd.Cells(LastRow, 1).Value = CDate(Me.TextBox1.Value)
wsd.Cells(LastRow, 2).Value = CDate(Me.TextBox2.Value)
wsd.Cells(LastRow, 3).Value = CDate(Me.TextBox3.Value)