Consulting

Results 1 to 4 of 4

Thread: User Form Date

  1. #1

    User Form Date

    Please Help!
    I have Excel spreadsheets, and a VBA form that takes input from the user and adds it to the Excel form. My problem i'm sure is a simple one, but its bugging me. I enter the date format in the text box as dd/mm/yyyy, and want it to print in the spreadsheet as same, however it prints as mm/dd/yyyy. Does anybody know what i'm doing wrong?
    Thanks in advance

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

    Range("A1").Value = CDate(TextBox1.Text)
    [/vba]

  3. #3
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    clairedon,

    I never trust VBA to do the right thing with m/d/yyyy or d/m/yyyy date formats. I recommend using unambiguous formats like d mmm yyyy, or doing things like using the Calendar or DateTimePicker controls, or using separate controls for month, day, and year.
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  4. #4
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    use a variable defined as date. put variable in cell.

    [vba]Option Explicit
    Sub test_format()
    Dim dt As Date
    dt = InputBox("Give date - xx/mm/yyyy", "Please give date ...")
    With Sheets(1)
    .Cells(ActiveCell.Row, ActiveCell.Column).Value = FormatDateTime(dt, 1)
    End With
    End Sub[/vba]

    Charlize

Posting Permissions

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