Consulting

Results 1 to 5 of 5

Thread: problem with date format when I use userform

  1. #1

    problem with date format when I use userform

    Hi,

    I have created a userform which contains text boxes and combo boxes. When I enter a date, e.g. 01/04/08 it populates cell with 04/1/08. If I enter, e.g 25/03/08 it displays OK.

    I have tried formating cell, but that doesn't work. I have also checked my regional settings too.

    Is it possible to enter, e.g. 010408 in the text box and for it to display 01/04/08 on the sheet.

    Thanks.

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    This is one way that should work......if your date is coming from the textbox.

    [vba]Private Sub CommandButton1_Click()
    Range("A1").Value = TextBox1.Value
    Range("A1").NumberFormat = "mm/dd/yy"
    End Sub[/vba]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Are you using UK or American date formats on your PC. Userforms by default use US display regardless.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    thanks Lucas, that worked great.

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    be sure to mark your thread solved using the thread tools at the top of the page.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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