+ Reply to Thread
Results 1 to 11 of 11

date format in VBA user form

Hybrid View

  1. #1
    Registered User
    Join Date
    12-12-2008
    Location
    UK
    Posts
    4

    date format in VBA user form

    Problem solved! Thanks to all responses. Appreciated.

    I have created a user form with a date field which fills a spreadsheet cell. The spreadsheet cell is formatted to dd/mm/yy but the user form will always enter as mm/dd/yy. Does anyone know how to edit the VBA form to use the dd/mm/yy format please. This is my first post so apologies if description of problem is obscure.
    Last edited by TerryWingfield; 12-16-2008 at 06:50 AM. Reason: SOLVED

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486
    Try These
    TextBox1 = Format(TextBox1, "dd/mm/yy")
    Range("C1") = Format(TextBox1, "dd/mm/yy")
    Range("D1") = Format(TextBox1, "[$-409]mmmm d, yyyy;@")

  3. #3
    Registered User
    Join Date
    12-12-2008
    Location
    UK
    Posts
    4
    Quote Originally Posted by davesexcel View Post
    Try These
    TextBox1 = Format(TextBox1, "dd/mm/yy")
    Range("C1") = Format(TextBox1, "dd/mm/yy")
    Range("D1") = Format(TextBox1, "[$-409]mmmm d, yyyy;@")
    Hello Dave

    I have tried your code (reproduced below)

    Private Sub txtBookingdate_Change()
    txtBookingdate = Format(txtBookingdate, "dd/mm/yy")

    End Sub

    but find it returns the date 30/12/1899 plus the first digit I enter. What am I doing wrong? txtBookingdate is the name of the text box in my UserForm.

    Thanks for your speedy response on Friday.

    Terry Wingfield

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291
    The Change event will fire for each keystroke you make. Try using the AfterUpdate or Exit events instead.

  5. #5
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    is this what you are after???


    TextBox1.Value = DateTime.Day(Date) & "/" & DateTime.Month(Date) & "/" & DateTime.Year(Date)
    on Userform Initialize
    I dont like to use code i dont understand
    it makes it hard to use in other situations
    so please try to be as clear and patent as possible with me

    Criticism is welcomed

  6. #6
    Registered User
    Join Date
    12-12-2008
    Location
    UK
    Posts
    4
    Thanks Friel

    That's done the trick

    regards
    Terry

  7. #7
    Registered User
    Join Date
    12-12-2008
    Location
    UK
    Posts
    4
    That helps thanks. My original problem which has not been solved, however, is that the date format I want in my spreadsheet is dd/mm/yy and is formatted as such but when I enter that format in the User Form it enters mm/dd/yy in the spreadsheet. Any thoughts?

  8. #8
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    couldnt you just insert the value of "textbox1" into the req'd cell?

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291
    If you are transferring the date via code, use CDate (assuming your system is set to UK format):
    Range("A1").value = CDate(Me.txtBookingdate.Value)
    for example.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You will need to make sure that you change the textbox name & destination cell
    ActiveCell.Value=Format(CDate(Me.TextBox1.Value,"short date"))
    You might be interested in this
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1