Consulting

Results 1 to 2 of 2

Thread: Solved: Date Saving Problem

  1. #1
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location

    Solved: Date Saving Problem

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Use

    [vba]

    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)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •