Results 1 to 5 of 5

TextBox Format

This is a discussion on TextBox Format within the Excel Questions forums, part of the Question Forums category; If I format a cell as mm/dd/yyyy and then I type into the cell only the month / day, the ...

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default TextBox Format

    If I format a cell as mm/dd/yyyy and then I type into the cell only the month / day, the year is automatically put in. I have a UserForm with a TextBox that I would like to act the same way so that when the user types in a date as 7/25, what the cell gets is 07/25/2003. I have spent several hours trying to figgure this out. Any ideas??

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,945

    Default Re: TextBox Format

    Do you have the TextBox and the cell linked ?
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default Re: TextBox Format

    I see no way in the properties for a TextBox to link it to a cell. Am I missing something here? I do have code that that puts the contants of the cell in the TextBox when the UserForm is open and puts the TextBox contents in the cell when a command button is clicked.

    I just did some checking, and a TextBox on a sheet can be linked to a cell, but on a UserForm, that provision is not there.

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,945

    Default Re: TextBox Format

    Well, actually there is a way, but good for you to not link cells ! (You use the ControlSource property for that).

    However, this seemed to work:


    Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    ****If TextBox2.Value Like "#/##" Or TextBox2.Value Like "##/##" Then
    ********TextBox2.Value = Format$(TextBox2.Value & "/" & Year(Date), "dd/mm/yy")
    ****End If
    End Sub


    Note that I used dd/mm/yy because that's the format I use on my computer... change that to mm/dd/yy to suit your needs.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  5. #5
    Board Regular
    Join Date
    Apr 2002
    Location
    Puerto Vallarta, Mexico
    Posts
    869

    Default Re: TextBox Format

    Thank you very much, Juan. That does the trick. Can you tell me why it is not good to link cells?

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
  •  


DMCA.com